【发布时间】:2017-12-09 17:05:05
【问题描述】:
在我的应用程序窗口中,我有两个 ItemPanels,它们在 RawLayout 内组织。
Item {
RowLayout {
anchors.fill: parent
spacing: 1
ItemPanel {
Layout.preferredWidth: 250
Layout.fillHeight: true
panelHeader: "Components"
DraggableItem {
width: 100; height: 100;
}
}
ItemPanel {
Layout.preferredWidth: 250
Layout.fillHeight: true
panelHeader: "Actions"
}
}
}
Components 面板包含DraggableItems。可拖放区域是Actions 面板。但如果我试图将DraggableItem 拖到Actions 面板,在我拖动它时它会被隐藏。
可拖动项目
Item {
id: root
property string colorKey: "red"
width: 64; height: 64
MouseArea {
id: mouseArea
width: 64; height: 64
anchors.centerIn: parent
drag.target: tile
onReleased: parent = tile.Drag.target !== null ? tile.Drag.target : root
Rectangle {
id: tile
width: 64; height: 64
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
color: colorKey
Drag.keys: [ colorKey ]
Drag.active: mouseArea.drag.active
Drag.hotSpot.x: 32
Drag.hotSpot.y: 32
states: State {
when: mouseArea.drag.active
ParentChange { target: tile; parent: root }
AnchorChanges { target: tile; anchors.verticalCenter: undefined; anchors.horizontalCenter: undefined }
}
}
}
}
我正在考虑添加一个透明图层并在拖动时将父图层更改为它,但我不知道如何在所有内容之上添加一个新图层。还有其他解决方法吗?
【问题讨论】:
-
您是否尝试过与
DraggableItem的z property 发生性关系,然后两者都大于ItemPanels? -
@folibis:
ItemPanel“组件”的 z 值应该更大。其子代的 z 值不太相关,除非它们重新成为ItemPanels 的兄弟姐妹。 -
将 z 值添加到 ItemPanel 不起作用。我为第一个 ItemPanel 添加了 z:1,在 Actions 面板中添加了 200。
-
当然,如果Actions-panel的z更大,它会再次失败。对象的
z-value越高,它的分层就越高 - 相对于兄弟姐妹。如果 z 值相同,则最后添加的将叠加在顶部。负值将使对象在父对象之下分层。 z 值始终只与兄弟姐妹相关。
标签: qt drag-and-drop qml