PDA

View Full Version : Model/View architecture in QTreeView, QTableView, and QGraphicsView widgets



vokov
13th May 2013, 16:57
I am working on an application that involves widgets based on QTreeView, QTableView, and QGraphicsView. However, I am finding it very difficult to organize the flow of data between these widgets using Qt's model/view architecture.

So, I am wondering if anyone could share their experience in high-level organization of such applications or, perhaps, recommend an alternative "design pattern"?

Right now I am thinking about implementing a custom class to manage the data and manually update the widgets when required. I realize that this will create a lot of redundancy (which I don't mind if makes the application less complex).

Thanks in advance!

Santosh Reddy
13th May 2013, 19:09
So, I am wondering if anyone could share their experience in high-level organization of such applications or, perhaps, recommend an alternative "design pattern"?
A little information about the application and kind of data and data flow is required before any constructive / helpful suggestions are made.


Right now I am thinking about implementing a custom class to manage the data and manually update the widgets when required. I realize that this will create a lot of redundancy (which I don't mind if makes the application less complex).
I will say Qt's MVC classes are well defined and are easy to use. As you already think a custom class (based on QAbstractItemModel or other derived ones) will work in most cases. Not sure of your application, but you can also explore using QTreeWidget, QTableWidget as they are quick and easy to start with out writing a custom model class. One important point when using Qt MVC is that try not to manually update the widgets in the view, let the view decided when to update the data, and make sure model informs the view about any change in the underlying data/model

alketi
14th May 2013, 05:10
High level answer:

We store our data with STL maps and vectors (to be GUI independent) and use the row and column indexes we get from the QTreeView as lookups into our data storage classes.