qt - Drag and Drop in QML TreeView -
in qml have treeview (properly working) multiselection:
treeview { id: treeview anchors.fill: parent model: mytestmodel selectionmode: selectionmode.extendedselection selection: itemselectionmodel { model: treeview.model } tableviewcolumn { role: "name_role" title: "name" width: 160 } tableviewcolumn { role: "type_role" title: "type" width: 75 } }
i'd implement drag & drop able "pull" items out of treeview droparea.
but when use approach found several times, namely defining itemdelegate contains mousearea, selection doesn't work anymore.
treeview { id: treeview anchors.fill: parent model: mytestmodel // broken due mousearea in itemdelegate ! selectionmode: selectionmode.extendedselection selection: itemselectionmodel { model: treeview.model } tableviewcolumn { role: "name_role" title: "name" width: 160 } tableviewcolumn { role: "type_role" title: "type" width: 75 } itemdelegate: item { rectangle { id: rect anchors.fill: parent color: styledata.selected ? "blue" : "transparent" text { anchors.verticalcenter: parent.verticalcenter color: styledata.selected ? "white" : "black" text: styledata.value } mousearea { anchors.fill: parent drag.target: symbolavatar onpressed: { var tmp = maptoitem(container, mouse.x, mouse.y); symbolavatar.x = tmp.x; symbolavatar.y = tmp.y; symbolavatar.dragging = true; symbolavatar.text = styledata.value; } } } } }
where symbolavatar item becomes visible when drag has started.
any ideas how implement drag , drop in qml treeview without breaking selection?
edit: using onpressandhold event handler inside treeview solution if access mouse position there, doesn't seem exist :-(
Comments
Post a Comment