Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTreeView: dragging and dropping items with left mouse button?
Forum Updated to NodeBB v4.3 + New Features

QTreeView: dragging and dropping items with left mouse button?

Scheduled Pinned Locked Moved General and Desktop
12 Posts 2 Posters 4.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on last edited by
    #3

    That's why I added "with the settings depicted above". I open the example, change those properties and observe the undesired behavior.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #4

      That's not enough. The example also provides a custom model. The model should also provide the Qt::ItemIsDragEnabled item flag as needed if you want your items to be draggable

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • V Offline
        V Offline
        Violet Giraffe
        wrote on last edited by
        #5
        This post is deleted!
        1 Reply Last reply
        0
        • V Offline
          V Offline
          Violet Giraffe
          wrote on last edited by
          #6
          This post is deleted!
          1 Reply Last reply
          0
          • V Offline
            V Offline
            Violet Giraffe
            wrote on last edited by Violet Giraffe
            #7

            Found what's breaking the drag and drop. It's my code that deselects an item that was single-clicked:

            void CFileListView::mousePressEvent(QMouseEvent *e)`
            {
            	const QModelIndex itemClicked = indexAt(e->pos());
            
                QTreeView::mousePressEvent(e);
            
                if (e->button() == Qt::LeftButton && itemClicked.isValid() && e->modifiers() == Qt::NoModifier)
            	    selectionModel()->clearSelection();
            }
            

            If I comment out the clearSelection call, drag and drop starts working. With clearSelection it's as if D&D is not enabled.
            No idea what exactly is happening or how to fix this.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #8

              To start a drag operation you need to select an index. What you do is that you clear that selection right after it happened so there's nothing to drag anymore.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • V Offline
                V Offline
                Violet Giraffe
                wrote on last edited by
                #9

                I see!
                Can I somehow start drag manually in the mouseMove event?

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #10

                  You would need to re-implement it yourself but why do you do that clear in the pressEvent ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    Violet Giraffe
                    wrote on last edited by Violet Giraffe
                    #11

                    This is a file manager application, this TreeView is the main file list view. Selection on click really looks horrible, and it's redundant - that's what the cursor is for (the thin dotted frame around an item). And not only that, but this selection upon click breaks other selection management operations.

                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      Violet Giraffe
                      wrote on last edited by
                      #12

                      So, there's no simple way to start dragging a specific item?

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved