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. [SOLVED] setRootIndex in QTreeView with multiple columns hides all but the first column

[SOLVED] setRootIndex in QTreeView with multiple columns hides all but the first column

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.7k 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.
  • F Offline
    F Offline
    fire112man
    wrote on last edited by
    #1

    Hi there

    I have some troubles with showing a QStandardItemModel in a QTreeview.
    I have built up my model as a QStandardItemModel with four columns like this
    @

    • Toplevel-Item 1
      | + Sublevel-Item 1
      | | + Data-Item 1 | Item Data | Item Data | Item Data
      | | + Data-Item 2 | Item Data | Item Data | Item Data
      | + Sublevel-Item 2
      | + Data-Item 3 | Item Data | Item Data | Item Data
      | + Data-Item 4 | Item Data | Item Data | Item Data
    • Toplevel-Item 2
      • Sublevel-Item 3
        | + Data-Item 5 | Item Data | Item Data | Item Data
        | + Data-Item 6 | Item Data | Item Data | Item Data
      • Sublevel-Item 4
        + Data-Item 7 | Item Data | Item Data | Item Data
        + Data-Item 8 | Item Data | Item Data | Item Data
        @
        The Toplevel-Items and Sublevel-Items have only one column while the Data-Items consist of four columns. If I add the model in my treeview with
        @
        mytreeview->setModel(mymodel);
        @
        everything is fine and I see the four columns as exspected. Now I want to see only the Sublevel-Items and Data-Items of Toplevel-Item 1. For this I set the root index to the first item with
        @
        mytreeview->setRootIndex(mymodel->index(0, 0));
        @
        I get only the subitems of the first Toplevel-Item, as I wanted. But now I see only the first column. The columns with the Item Data are not displayed in my view any more.

    What is my mistake or am I missing something here?

    Thanks in advance
    fire112man

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fire112man
      wrote on last edited by
      #2

      I got a possible solution for this problem. For those who are struggeling with the same issue, here is, what I did:
      QTreeview shows only as many columns as the Toplevel-item with the most columns has. It doesnt matter, how many columns the children have. I order to show all four columns when I change the root index, I have to make sure, that at least one of the new Toplevel-Items, in the example above the Sublevel-Items, has four columns.
      So I added three more columns in the row of Sublevel-Item 1 and now it is working.

      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