Results 1 to 3 of 3

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

  1. #1
    Join Date
    Oct 2012
    Posts
    3
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Model/View architecture in QTreeView, QTableView, and QGraphicsView widgets

    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!

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Model/View architecture in QTreeView, QTableView, and QGraphicsView widgets

    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
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Dec 2011
    Posts
    60
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Model/View architecture in QTreeView, QTableView, and QGraphicsView widgets

    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.

Similar Threads

  1. Questions regarding Model-View Architecture
    By zgulser in forum Qt Programming
    Replies: 0
    Last Post: 14th March 2012, 16:03
  2. Using Qt::UserRole in the Model/View architecture
    By d_stranz in forum Qt Programming
    Replies: 8
    Last Post: 23rd January 2011, 16:13
  3. Questions about Model-View Architecture in QT
    By Polnareff in forum Newbie
    Replies: 4
    Last Post: 4th June 2010, 15:01
  4. Replies: 3
    Last Post: 30th March 2010, 13:06
  5. Replies: 1
    Last Post: 30th November 2007, 11:55

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.