[SOLVED] setRootIndex in QTreeView with multiple columns hides all but the first column
-
wrote on 17 Dec 2014, 09:51 last edited by
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.
- Sublevel-Item 3
What is my mistake or am I missing something here?
Thanks in advance
fire112man - Toplevel-Item 1
-
wrote on 17 Dec 2014, 13:10 last edited by
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/2