0
votes

I have a simple task but am struggling with the proper way to implement it:

  • I want one shared QStandardItemModel containing a tree structure to be displayed in two different QTreeViews.
  • The first QTreeView shows the model as-is and allows the user to add, remove and rearrange the items. Clicking an item shows an item-associated QWidget within a QStackedWidget below the QTreeView. Some item types can also be renamed.
  • The second QTreeView shows the same tree model, however all items are greyed out by default. A Processor will then move along the tree structure and process each item. Whenever an item is processed, it should not longer be greyed out. Those items not greyed out should be clickable to display the item-corresponding processed image in a viewer. Whenever a change is made in the first QTreeView, the Processor starts processing from the changed position onwards again.

How do I implement the different look and functionality of the two QTreeViews? Do I assign custom QItemDelegates to each QTreeView? Should I use a QIdentityProxyModel for the second QTreeView?

1

1 Answers

0
votes

It is only necessary to use a QStandardItemModel for both models since they store the same information so if you want them to look different then you must use delegates.

If you want some action when the view is clicked then that does not depend on the model but you have to use the view clicked signal that is independent of the other view.

For the second view if a delegate is required to change the color, the logic is to use a role to indicate if that item has been processed or not, and then change the color based on that role. When you say "a change in the first QTreeView" you should actually say "a change in the model" so it is only necessary to use the dataChanged signal, process the item by changing the role status before and after processing.