Managing multiple data sources
-
Hello, I'm currently tackling a task involving hierarchical data items, and I've opted to utilize QtTreeView, QStandardItem, and QStandardItemModel. Each label in the tree view corresponds to its own dataset. My goal is to efficiently store and display all this data using a single widget. The functionality I'm aiming for is that when I click on a tree view entry, the associated data should be presented on the widget. Additionally, any edits made to the data should be updated in the corresponding data source. I also want to store the widget's state when switching to a different tree item.
In my attempts to achieve this, I experimented with QStandardItem to associate widgets with their respective data. I stored their UI in a stacked widget, resulting in a stacked widget with entries equal to the number of elements in the tree view. This way, when an item is selected, the index of the stored widget becomes the current one. However, I'm unsatisfied with this implementation and believe there might be a more effective approach. I would appreciate any suggestions for a better implementation. Thanks!
Note that I'm a Qt noob, I've been using Qt for less than 2 months. -
Hi and welcome to devnet,
Looks like you might want to check QDataWidgetMapper.
You are correct that creating one widget per entry in your view is not a good design choice.