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. QTreeWidget - drag and drop
Forum Updated to NodeBB v4.3 + New Features

QTreeWidget - drag and drop

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 661 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.
  • G Offline
    G Offline
    Grimface
    wrote on last edited by
    #1

    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?

    Pl45m4P 1 Reply Last reply
    0
    • G Grimface

      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?

      Pl45m4P Online
      Pl45m4P Online
      Pl45m4
      wrote on last edited by
      #2

      @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.

      • https://doc.qt.io/qt-6/qtreewidget.html#dropEvent

      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      G 1 Reply Last reply
      0
      • Pl45m4P Pl45m4

        @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.

        • https://doc.qt.io/qt-6/qtreewidget.html#dropEvent
        G Offline
        G Offline
        Grimface
        wrote on last edited by
        #3

        @Pl45m4 Thanks. I've been sidetracked working on other things lately. I'll have a look into reimplementing the dropevent.

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

          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.

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

          G 1 Reply Last reply
          0
          • SGaistS SGaist

            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.

            G Offline
            G Offline
            Grimface
            wrote on last edited by
            #5

            @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)?

            SGaistS 1 Reply Last reply
            0
            • G Grimface

              @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)?

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Grimface reimplement these methods and reject the proposed action when adequate.

              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

              • Login

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