GridView를 사용하여 ListModel을 표시했습니다. 3 열 그리드를 만들QT quick2 qml 동적 변경 GridView 열
cellWidth = grid.width/3
: 원래 난에 cellWidth을 설정합니다. 그때 나는 열이 2로 계산 변경하려면, 그래서에 cellWidth를 설정 한 다음의 GridView의 화면이 변경된 경우
cellWidth = grid.width/2
. 그러나 컨테이너의 바탕 화면 창 크기를 조정하면 Gridview의 셀이 더 이상 크기를 변경하지 않습니다.
수정하려면 어떻게해야합니까? 내가있는 gridview의 onWidthChanged를 정의하여 문제를 해결 한
import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Window 2.0
ApplicationWindow {
title: qsTr("Hello World")
width: 640
height: 480
menuBar: MenuBar {
Menu {
title: qsTr("File")
MenuItem {
text: qsTr("2 columns")
onTriggered: grid.cellWidth = grid.width/2;
}
MenuItem {
text: qsTr("3 columns")
onTriggered: grid.cellWidth = grid.width/3;
}
}
}
GridView {
id: grid
anchors.fill: parent
cellWidth: width/3;
cellHeight: 300;
model: ListModel {
ListElement {
name: "Apple"
cost: 2.45
}
ListElement {
name: "Orange"
cost: 3.25
}
ListElement {
name: "Banana"
cost: 1.95
}
}
delegate : Rectangle {
//anchors.fill: parent
width: grid.cellWidth
height: grid.cellHeight
border.color: "green"
border.width: 2
color: "red"
}
}
}
사람들이 코드를 시도하고 도움을 줄 수 있도록 더 많은 코드를 보여줄 필요가 있다고 생각합니다. – Kunal
@Kunal tks, 일부 코드를 붙여 넣었습니다. – Brent81