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. QAbstractIItemModel for QTreeView with movable items
Qt 6.11 is out! See what's new in the release blog

QAbstractIItemModel for QTreeView with movable items

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.3k 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.
  • HarbH Offline
    HarbH Offline
    Harb
    wrote on last edited by
    #1

    Hi!
    I want to implement QAbstractItemModel, so that it will provide data for QTreeView. So, internal data is organized to the tree structure. Also I want to make QTreeView interactive, so user could move items from parent to another parent, up and down. Now I am a little bit confused what methodes of QAbstractItemModel I should implement for that. Should I implement drag/drop methodes? Or moveRows is enought?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi and welcome
      Did you see this example ?
      http://doc.qt.io/qt-5/qtwidgets-itemviews-editabletreemodel-example.html

      and
      http://doc.qt.io/qt-5/model-view-programming.html#model-subclassing-reference

      If you just want to be able to rearrange the items, maybe the default drag and drop is enough.
      Its off pr default.
      old doc ( sorry my goggle foo failed)
      https://doc.qt.io/archives/4.6/model-view-dnd.html

      1 Reply Last reply
      3
      • HarbH Offline
        HarbH Offline
        Harb
        wrote on last edited by
        #3

        Tnx, mrjj!

        http://doc.qt.io/qt-5/model-view-programming.html#using-drag-and-drop-with-item-views
        This is the new doc where drag and drop is described. Well, I played around a little bit with QTreeView and QAbstractItemModel, and I was surpirsed that when I do drag/drop opeartions QAbstractItemModel::insertRows and QAbstractItemModel::removeRows are invoked. I thought that QAbstractItemModel::moveRows would. I don't understand how should I implement my internal tree data structure changes inside these methodes? With moveRows it would be quite straightforward

        mrjjM 1 Reply Last reply
        1
        • HarbH Harb

          Tnx, mrjj!

          http://doc.qt.io/qt-5/model-view-programming.html#using-drag-and-drop-with-item-views
          This is the new doc where drag and drop is described. Well, I played around a little bit with QTreeView and QAbstractItemModel, and I was surpirsed that when I do drag/drop opeartions QAbstractItemModel::insertRows and QAbstractItemModel::removeRows are invoked. I thought that QAbstractItemModel::moveRows would. I don't understand how should I implement my internal tree data structure changes inside these methodes? With moveRows it would be quite straightforward

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Harb said in QAbstractIItemModel for QTreeView with movable items:

          Hi
          they both seems to be part of "move items" feature.
          For removeRows , docs says
          "WThe base class implementation does nothing and returns false."

          So maybe you can just use moveRows and it works.

          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