Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-137090

QTreeView always deletes item on drag if the receiving application report a "Move" executed action.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.9.0
    • None
    • Windows 10
      PySide 6.9.0
    • Windows

    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

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            pylessard PY Lessard
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes