PDA

View Full Version : Need to remove root node from QTreeView



tescik
23rd April 2014, 23:55
Hi
I'm new to QT and I'm trying to implement a TreeView from a QDomNode created manually. The problem I'm facing is that the resulting node has the following structure:
root -->
AA
BB
CC

And of course that when setting the model in QTreeView I have the same structure, but what I need is to show in the QTreeView the 2 level:

AA
BB
CC

I had been searching in the forum for some ideas but I must say that I didn't found any...

Is there any way to achieve this?

ChrisW67
24th April 2014, 00:35
QTreeView::setRootIsDecorated() and/or QTreeView::setRootIndex()

tescik
24th April 2014, 10:15
Thank you for the replay!

I tried using these 2 functions but I don't get the desired result! The problem with setRootIndex is that if I use it like this:
QModelIndex parentIndex = myModel->index(0,0);
QModelIndex newIndex = myModel->index(0,0, parentIndex);
myTree->setRootIndex(newIndex);

I actually get the childs of AA ! not even the AA-parent is shown!!!

anda_skoa
24th April 2014, 10:48
Looks like you are going down one level too much.
Initially the root index is QModelIndex(), you want index(0, 0), but you are setting index(0, 0, index(0, 0)

Cheers,
_

tescik
24th April 2014, 10:54
THANK YOU!!!!!
You were right: myTree->setRootIndex( myModel->index(0,0));
did the trick and now I have the desired structure in my view:
AA
BB
CC