Hello,
I am converting a item-based QTreeWidget into a model-based QTreeView.
I am rendering a QTreeView using a custom model based on QAbstractItemModel. My data model has a bool property called "expanded": that property indicate whether if the node must be expanded or collapsed.
Previously, when the QTreeWidgetItems were created in a for-loop, it was easy to call setExpanded(data->isExpanded()). Now that my data is rendered using a view, I am confused on how I should accomplish this.
Up to now, after I call setModel() on the model object, I use a for-loop to iterate through my model (if the property isExpanded is set in the data model, I call expand() on the tree view).
Works well, but it doesn't look like the optimal solution here. I would have thought that a delegate would take care of this, but as far as I understand it, it is the View's job to manage the tree items... do I have it right? If so, do I have to subclass QTreeView in order to do what I want (The view is for the display only, when the model is loaded, the nodes are reset to the state indicated in the data, we do not save the node state afterwards)?
Bookmarks