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 internal move: not all columns shown
Forum Updated to NodeBB v4.3 + New Features

QTreeView internal move: not all columns shown

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 357 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.
  • Joel BodenmannJ Offline
    Joel BodenmannJ Offline
    Joel Bodenmann
    wrote on last edited by Joel Bodenmann
    #1

    Simple scenario: QStandardItemModel, QTreeView and a QSortFilterProxyModel.

    So far, everything is working as expected. Now I'm working on a feature allowing the user to create a new group (item in the tree view) and then adding existing items into that group (re-parenting via QAbstractItemView::InternalMove).

    While the row is being moved as expected, not all columns show up anymore.
    Here are two screenshots: Before the move and after the move.

    Before move:

    deleteme_ss_qtreeview_01.png

    After moving the row with ID 5 to the group Test Group 1:
    deleteme_ss_qtreeview_02.png

    My expectation would have been that after the move (re-parenting), the row would still show all columns (ID, Name and Description). But instead, only the Description column is shown.

    Why is this happening and how can I achieve the expected behavior in that each row still populates/shows all the columns accordingly but is just nested in zero or more parent groups?

    Industrial process automation software: https://simulton.com
    Embedded Graphics & GUI library: https://ugfx.io

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

      Hi,

      Did you check that it is the correct index that is moved ? I.e that it's the first column index that you move ?

      Do you have the same issue without the proxy ?

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

      Joel BodenmannJ 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        Did you check that it is the correct index that is moved ? I.e that it's the first column index that you move ?

        Do you have the same issue without the proxy ?

        Joel BodenmannJ Offline
        Joel BodenmannJ Offline
        Joel Bodenmann
        wrote on last edited by
        #3

        @SGaist said in QTreeView internal move: not all columns shown:

        I.e that it's the first column index that you move ?

        Sorry for the late reply. Your question kind of threw me off. I didn't understand why you'd ask this. As per my understanding this shouldn't matter as I want to remove an entire row. However, knowing you (minus the outstanding beer) I was fairly sure that you wouldn't ask this unless it would be important. Hence I needed some time to think about it :D

        So what basically happened is that I only set the Qt::ItemIsDragEnabled flag on ONE item of the row (eg. cell). Hence the other items were not moved (although the row still disappeared in the view). Once I added the Qt::ItemIsDragEnabled flag to all items of the row things started looking more the way I expected.

        As mentioned this is my first time using QStandardItemModel. I haven't really faced this issue previously as I'd simply subclass QAbstractItemModel and implementing itemFlags() accordingly.
        I feel like I am using the QStandardItemModel incorrectly. To achieve the visual appearance showed in my initial screenshot I am creating three QStandardItems for each row and adding them using invisibleRootItem()->appendRow():

        void
        model::add(const process& p)
        {
            const Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
        
            // ID
            auto item_id = new QStandardItem();
            item_id->setText(QString::number(p.id));
            item_id->setFlags(flags);
        
            // Name
            auto item_name = new QStandardItem();
            item_name->setText(p.name);
            item_name->setFlags(flags);
        
            // Description
            auto item_description = new QStandardItem();
            item_description->setText(p.description);
            item_description->setFlags(flags);
        
            invisibleRootItem()->appendRow({ item_id, item_name, item_description });
        }
        

        Is this the way to go? It just doesn't feel right.

        Industrial process automation software: https://simulton.com
        Embedded Graphics & GUI library: https://ugfx.io

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

          I don't see anything wrong. The invisible root item is the initial item that allows to keep together all the others. Whether you have a tree like model or table like does not matter.

          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
          • Joel BodenmannJ Offline
            Joel BodenmannJ Offline
            Joel Bodenmann
            wrote on last edited by Joel Bodenmann
            #5

            Alright, after getting this to work I decided to not use QStandardItemModel anymore but instead directly deriving from QAbstractItemModel as I've usually done. It was a fun little adventure tho.

            Thank you for your help!

            Industrial process automation software: https://simulton.com
            Embedded Graphics & GUI library: https://ugfx.io

            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