나는 QML의 초보자이며 "아코디언"항목을 만들었습니다. 나는 완전한 QML 프로젝트를 수정했다. 이를 위해 , 나는 PanelItems 사용 "드래그를 사용하는 동안 내가 성공 이제ColumnLayout에서 위치를 변경하는 방법
, 나는 것이 가능 columnLayout도에서 두 개의 서로 다른 PanelItems 사이에 위치를 교환 할 수 있도록하고 싶었
Item {
default property var contentItem: null
property string title: "panel"
id: root
Layout.fillWidth: true
height: 30
Layout.fillHeight: current
property bool current: false
ColumnLayout {
anchors.fill: parent
spacing: 0
Rectangle {
Drag.active: dragArea.drag.active
id: bar
Layout.fillWidth: true
height: 30
color: root.current ? "#81BEF7" : "#CEECF5"
Text {
anchors.fill: parent
anchors.margins: 10
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
text: root.title
}
Text {
anchors{
right: parent.right
top: parent.top
bottom: parent.bottom
margins: 10
}
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: "^"
rotation: root.current ? "180" : 0
}
MouseArea {
id: dragArea
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
drag.axis: Drag.YAxis
drag.target: root
onReleased: {
console.log("release !")
root.Drag.drop()
}
onClicked: {
if (root.parent.current !== root) {
console.log('test');
// if((root.parent.currentItem !== null))
// root.parent.currentItem.current = false;
root.current = !root.current;
root.parent.currentItem = root;
}
}
}
}
Rectangle {
id: container
Layout.fillWidth: true
anchors.top: bar.bottom
implicitHeight: root.height - bar.height
clip: true
Behavior on implicitHeight {
PropertyAnimation { duration: 100 }
}
}
Component.onCompleted: {
if(root.contentItem !== null)
root.contentItem.parent = container;
}
}
}
PanelItem.qml 및 드롭 "functionnalities.
지금은 항목을 드래그 앤 드롭 할 수 있지만 항목간에 위치를 바꾸는 방법을 모르겠습니다.
여기 내 주요입니다 :
ApplicationWindow {
visible: true
width: 400
height: 400
ColumnLayout {
anchors.fill: parent
spacing: 1
id: test
property var currentItem: null
PanelItem {
title: "Panel 1"
Rectangle {
color: "orange"
anchors.fill: parent
}
}
PanelItem {
title: "Panel 2"
Rectangle {
color: "lightgreen"
anchors.fill: parent
}
}
PanelItem {
title: "Panel 3"
Rectangle {
color: "lightblue"
anchors.fill: parent
}
}
PanelItem {
title: "Panel 4"
Rectangle {
color: "yellow"
anchors.fill: parent
}
}
Item {
Layout.fillWidth: true
Layout.fillHeight: true
}
}
}
main.qml
나는 어쩌면 ListView에 함께 할 것을 시도해야하지만 난 내 PanelItems와 함께 작동 할 수 없습니다 읽어 보시기 바랍니다.
의견이 있으십니까? 나는 QML, Views 등으로 조금 잃었다.
고마워!
안녕하세요 덤으로
ColumnLayout
및Repeater
를 대체되었습니다. 답변 해 주셔서 감사합니다. 나는 당신이 말한 것처럼 ListView를 사용하기로하지만 항목의 색인을 업데이트하려고하기 전에 ListView에 아코디언을 삽입하는 데 어려움이 있습니다. 시간이 있으시면 [thread] (http://stackoverflow.com/questions/43230739/how-to-use-a-listview-with-custom-item-qml)을 확인하십시오. 좋은 하루 되세요! –