QTreeWidget - drag and drop
-
Hi,
can anyone give me some pointers on how to disallow certain drag and drop moves within a QTreeWidget?
I've enabled drag/drop functionality in QTreeWidget e.g.
ui->myTree->setDragEnabled(true);I'd like when a user drags an item, and attempts to drop it, that when they let the mouse button go it springs back to its initial position (if it's an 'illegal' move). Is this type of functionality already built in to QTreeWidget?
-
Hi,
can anyone give me some pointers on how to disallow certain drag and drop moves within a QTreeWidget?
I've enabled drag/drop functionality in QTreeWidget e.g.
ui->myTree->setDragEnabled(true);I'd like when a user drags an item, and attempts to drop it, that when they let the mouse button go it springs back to its initial position (if it's an 'illegal' move). Is this type of functionality already built in to QTreeWidget?
@Grimface said in QTreeWidget - drag and drop:
I'd like when a user drags an item, and attempts to drop it, that when they let the mouse button go it springs back to its initial position (if it's an 'illegal' move). Is this type of functionality already built in to QTreeWidget?
Reimplement the
dropEvent
and ignore it, when your "illegal" condition is met. -
@Grimface said in QTreeWidget - drag and drop:
I'd like when a user drags an item, and attempts to drop it, that when they let the mouse button go it springs back to its initial position (if it's an 'illegal' move). Is this type of functionality already built in to QTreeWidget?
Reimplement the
dropEvent
and ignore it, when your "illegal" condition is met. -
Hi,
If you want things to be clean, you should also implement the dragEnterEvent and/or dragMoveEvent methods. The issue with only implementing dropEvent is that your users will not be made aware that their action is not allowed.
-
Hi,
If you want things to be clean, you should also implement the dragEnterEvent and/or dragMoveEvent methods. The issue with only implementing dropEvent is that your users will not be made aware that their action is not allowed.
@SGaist Thanks for the tips. When an item is dragged from the tree, to say a button or a panel, a small icon is shown (i.e. white circle with red line through it) indicating that this is an illegal move. How would I implement such a thing myself so that this icon is shown when trying to move a tree item onto another tree item (where I don't want the move to be possible)?
-
@SGaist Thanks for the tips. When an item is dragged from the tree, to say a button or a panel, a small icon is shown (i.e. white circle with red line through it) indicating that this is an illegal move. How would I implement such a thing myself so that this icon is shown when trying to move a tree item onto another tree item (where I don't want the move to be possible)?