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. How to move items in a qtreewidget?

How to move items in a qtreewidget?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 1.5k Views
  • 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.
  • O Offline
    O Offline
    OpenGL
    wrote on last edited by
    #1

    I wonder if someone could show me an example how to move qtreewidgetitems in a qtreewidget?

    I would like to move an item, and all its sub items, to a new place in the tree. I guess that could be triggered by drawing the item with the mouse.

    1 Reply Last reply
    0
    • gde23G Offline
      gde23G Offline
      gde23
      wrote on last edited by gde23
      #2

      Take a look at the example here

      basically you nee to subclass the model and then implement
      flags() as well as mimeData() and dropMimeData()

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Bonnie
        wrote on last edited by Bonnie
        #3

        QTreeWidget is already implemented to drag & drop.
        You can just enable that by setDragDropMode(QAbstractItemView::InternalMove).
        After that all the items with Qt::ItemIsDragEnabled / Qt::ItemIsDropEnabled flag will be able to be dragged / dropped.
        But it is not well controlled. For example, you cannot limit a item to be moved to only the same level.

        1 Reply Last reply
        2
        • O Offline
          O Offline
          OpenGL
          wrote on last edited by
          #4

          But how can I find out what item was dragged and on what item it was dropped?

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

            Hi,

            Why do you need that information for ?

            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

            • Login

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