PDA

View Full Version : How to "share" a QTreeWidget



cszawisza
2nd September 2013, 18:42
Hi.

I'm working on a application that uses couple of windows, and couple of them uses the same QThreeWidget, my question is
Is there a simple way to share the same qtreewidget (or only the information of item expands and selections) between different QDialogs?

Infinity
2nd September 2013, 18:58
Use a QTreeView instead of a QTreeWidget. You can set the same instance of your model to multiple instances of QTreeView.
See: http://qt-project.org/doc/qt-5.0/qtwidgets/qtreeview.html

cszawisza
7th September 2013, 14:04
OK.
I read about QTreeView... and don't find any simple answer. What i need to do is make a tree trom data stored in table


NAME | ParaneID | ID | Description
foo | 0 | 1 | Some entry
bar | 1 | 2 | another entry




name DESC
|-> FOO Some entry
|-> BAR another entry


I need to store in my model Name, description and ID. In QTreeWidget I create a item, setText (0,name); (1,ID); (2,desc) and add the item as root (if parent = 0) or as a child of different entry. How can I do it with QStandardItemModel? Only thing I found is an example where are entries with children having only one column... I need multiple columns in children.

cszawisza
7th September 2013, 20:11
Sory for 2 posts in row but I don't know how edit last one...
The thing I was missing is


void QStandardItem::setChild(int row, int column, QStandardItem * item)

function :)

ChrisW67
9th September 2013, 03:14
QTreeWidgets are independent of each other with separate data and selections. A shared selection is only really sensible if the underlying data model is also shared.

If you want the same data presented in three view then you should use QTreeView and a separate model. You can build a usable tree model with QStandardItemModel or write your own custom model.
If you have three views sharing the same model and want the same current and selected items in each then point them all at the same QItemSelectionModel (i.e. share one).