qt - Drag and Drop mechanism in qml
问题描述
I have a row consists of 10 rectangles, each rectangle can be dragged to another area, this what I have made, but I need to drag a part of the rectangles, not all of them example: the user can drag 5 rectangle at once, or he can drag 3 rectangles at once or dragging 7 rectangles at one.
here is my code:
Row {
id: rowLayout
property int index: 9
width: bottomRectangle.width * 0.5
height: bottomRectangle.height * 0.5
anchors.centerIn: parent
Repeater {
id: repeater
model: 10
Rectangle {
id: unitItem
width: rowLayout.width * 0.1
height: rowLayout.height * 0.5
color: "#80F16F6F"
border.width: 5
border.color: "#FFF16F6F"
radius: 10
Drag.active: dragArea.drag.active
Drag.hotSpot.x: parent.width / 2
Drag.hotSpot.y: parent.height / 2
MouseArea {
id: dragArea
anchors.fill: parent
drag.target: unitItem
onReleased: {
parent = unitItem.Drag.target !== null ? unitItem.Drag.target : dropArea
unitItem.Drag.drop()
}
}
states: [
State {
when: dragArea.drag.active
ParentChange { target: unitItem; parent: dropArea }
AnchorChanges { target: unitItem; anchors.verticalCenter: undefined; anchors.horizontalCenter: undefined }
}
]
}
}
}
at this point, each rectangle can be dragged at its own. But I need to drag 6 rectangles for example all at once. any ideas for that?
解决方案
推荐阅读
- reactjs - 如何将缺少的依赖项添加到仅运行一次的 useEffect 挂钩?
- sql - 在一组日期之间查找季度结束日期 - Oracle SQL
- bootstrap-4 - 行中的引导图像对齐
- google-pay - 在没有 UI 的情况下生成 Google Pay 令牌
- android - 在android中的方向更改期间无法恢复表行
- sql - ORacle KEEP DENSE_RANK FIRST 的 Postgres 转换
- c# - 直接部署到 SQL Server 的集成服务
- html - 尝试在每个 50/50 100%Width 旁边创建带有图像和文本框的可堆叠容器?
- c++ - 基于预加载器的锁分析器中的“Futex 工具返回了意外的错误代码”
- java - AWS CDK - 如何防止它创建默认目标组?