Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.9.0
-
None
-
Windows 10
PySide 6.9.0
Description
I filed this issue as a bug, it's more of a unwanted feature I think or lack of option to disable a default behaviour.
Problem
It is impossible to make a QTreeView that allow internal move without allowing to delete items by dragging them to a different application.
Details
When we drag an item from a QTreeView, if the executed action is a "Move", the item is automatically deleted. See excerpt of code here : https://github.com/qt/qtbase/blob/dev/src/widgets/itemviews/qabstractitemview.cpp#L3895-L3896
It is possible to drag an item outside the application. On Windows at least, the receiving application decides of the executed action regardless of the default action. Because of that, dragging on an external application can cause a deletion in the QTreeView, even if unwanted. I believe this default behaviour should be avoidable; I think it assumes that the tree view will display the file system, which might not be true (it's not in my case).
The only feature that could prevent that would be to disable the "Move" action, but then, internal move becomes impossibles.
Important notes, some applications accepts a drags always, regardless of the mime type. Using a custom mime type does not do it. For example:
- VsCode editor window
- Firefox bookmark menu
Possible solutions
I think this problem could easily be avoided by one of these (or many of them):
- Add an option on the QTreeView to disable the condition in the linked code
- Let the user disable auto-deletion if the drop happens outside of the application QDrag::target() returns Null
- Add an overridable callback inside QTreeView to accept/refuse to process the QDrag result.
- Make the QAbstractItemViewPrivate::RenderToPixmap() public so we can override QTreeView::startDrag without rewriting the whole drag logic.
Resources
- Video : 2025-05-21-21-32-55.mp4
Shows that a drop into VsCode accepts anything (mime type: "potato/tomato") and the action is "Move"
- test_drag_n_drop.py
: To reproduce using PySide6
- Reddit Thread : Where the issue was firstly discussed.