Restrict what can be dragged from a QTreeView
-
I really will keep this one brief! :)
Code has a
QTreeView
. It allows dragging of elements out to aQGraphicsView
. I didn't write any of the code for this, haven't done drag & drop. There's no MIME stuff, no code I can see in the treeview side, no creation of drag objects, just:self.treeView_blklib.setDragEnabled(True) self.treeView_blklib.setDragDropOverwriteMode(True) self.treeView_blklib.setDragDropMode(QtWidgets.QAbstractItemView.DragOnly)
so I guess that all works internally.
All I want to know is: I want to restrict so that the tree leaves can still be dragged but the nodes cannot. How simply can that be achieved? Do I have to perhaps introduce a mouse-down handler and do something there?
-
Overwrite QAbstractItemModel::flags()
-
@Christian-Ehrlicher
I wondered whether there might be a flag for dragable on my way home after I posted! I see https://doc.qt.io/qt-5/qt.html#ItemFlag-enum,Qt::ItemIsDragEnabled 4 It can be dragged.
. Perfecto-mundo, thank you :)