PDA

View Full Version : About tree organization...



Patrick Sorcery
3rd September 2010, 03:56
Hello. I'm meeting a problem & I'll try my best to describe...

I decide to organize my objects in a tree structure and show them in a QTreeWidget, so I put a QStandardItem as a member in each class, use a QStandardItemModel to manage them and then use QTreeView::setModel() to show them in a QTreeView.

But now I want to get the pointer of the object which is currently selected and I don't know how... it seems QTreeView doesn't have a method to get current item, and even if it has I don't know how to get the object's pointer from the item's pointer...

BTW, what's the difference between QTreeView & QTreeWidget? I'm totally new in GUI making...

Thanx!

Lykurg
3rd September 2010, 07:30
To get the current item have a look at QAbstractItemView::selectionModel(). Second, don't put a standard item to the classed as their members. Simple construct them for the model only. And if you don't write a custom model for your needs you can receive the pointer to your object when you use QStandardItem::setData() with user role and an appropriate value.

wysota
3rd September 2010, 07:43
QTreeView is model based, QTreeWidget is item based. To get selection in the tree view, access its selectionModel().