Results 1 to 8 of 8

Thread: QSqlRelationalTableModel looks flat in QTreeView

  1. #1
    Join Date
    Jun 2012
    Posts
    219
    Thanks
    28
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QSqlRelationalTableModel looks flat in QTreeView

    I set up a QSqlRelationalTableModel for a QTreeView using a QSqlRelation to associate a key in two different tables.

    I expected the QTreeView to show a parent/child relationship (a tree) based on the QSqlRelation, but it looks flat like the QTableView. Is this the expected behavior?

    I wanted something that would expand when I clicked on the parent to show child records. For example, I have a "clubs" table with team names, and a different table "dogs" that are associated with an id. I hoped the QTreeView would show only field(s) from the club table until a row was clicked to "drill down" to display the associated records from the dogs table.

    Do I need to do a custom model for this? Is there any point in doing a model/view approach instead of the simpler QTreeWidget, if I have to do a custom model anyway?

    Thanks,

    Dave Thomas

  2. #2
    Join Date
    Jun 2012
    Posts
    219
    Thanks
    28
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlRelationalTableModel looks flat in QTreeView

    So, it looks like I need to do something like I see in

    examples/itemviews/simpletreemodel

    Is that correct, or am I missing some easier way?

    Thanks,

    Dave Thomas

  3. #3
    Join Date
    Jun 2012
    Posts
    219
    Thanks
    28
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlRelationalTableModel looks flat in QTreeView

    Wow, the silence is deafening on this one. Maybe know one knows enough to reply or perhaps I've been offensive some how.

    If it's the latter, it was intentional, and accept my apology.

    I found class that does what I need: SqlTreeModel. I found it here:

    http://www.mimec.org/node/300

    Dave Thomas

    http://www.mimec.org/node/300

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlRelationalTableModel looks flat in QTreeView

    Sorry, I missed your thread completely. That's what usually happens if one replies to his own posts

    QSqlRelationalTableModel is a flat model, nothing will make it build a tree.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jun 2012
    Posts
    219
    Thanks
    28
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlRelationalTableModel looks flat in QTreeView

    Thanks for replying.

    So, while the SqlTreeModel class works, I'm still wondering if there is any advantage to doing a model/view tree instead of an item based tree for Sql query based data.

    As I understand it, the advantage of the model/view approach is that multiple views can be used for the same data model. But, I don't see more than one view available for a tree. So, why bother to do model/view for a tree versus just a tree widget?

    Also,in either case, the data source will actually be the database. Either I copy data from there into a tree model, or to an item based tree widget. I have to do all the work to keep those copies of the data in sync with the database.

    What's the intended advantage of a QTreeModel/QTreeView versus the item based tree widget?

    Thanks,

    Dave Thomas

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSqlRelationalTableModel looks flat in QTreeView

    Quote Originally Posted by davethomaspilot View Post
    Do I need to do a custom model for this? Is there any point in doing a model/view approach instead of the simpler QTreeWidget, if I have to do a custom model anyway?
    Yes. There is a point to a model rather than using a QTreeWidget if you want more than one view on the data at the same time.

  7. #7
    Join Date
    Jun 2012
    Posts
    219
    Thanks
    28
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlRelationalTableModel looks flat in QTreeView

    But, isn't there only one view widget for tree structures available in Qt? Or do you mean multiple instances of that treeview on the same data model?

    Thanks,

    Dave Thomas

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlRelationalTableModel looks flat in QTreeView

    Quote Originally Posted by davethomaspilot View Post
    But, isn't there only one view widget for tree structures available in Qt? Or do you mean multiple instances of that treeview on the same data model?
    You can show a tree model in a QTableView or a QListView as well.

    Another advantage of having proper models over convenience views such as QTreeWidget is less data redundancy. If you have some data and you want to put it into QTreeWidget, you have to effectively make a copy of the data (unless you want to reimplement have a dozen different things). With a model approach you only need to access your original data.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Flat QScrollArea
    By Animator1 in forum Qt Programming
    Replies: 4
    Last Post: 27th March 2011, 18:18
  2. make a flat QPushButton
    By harmodrew in forum Newbie
    Replies: 2
    Last Post: 6th August 2010, 16:46
  3. hierarchical model in a flat view
    By gniking in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2009, 20:17
  4. Flat data source for QTreeView/Model
    By mawt in forum Qt Programming
    Replies: 1
    Last Post: 18th October 2009, 16:20
  5. Flat Icon in a QToolBar
    By schall_l in forum Qt Programming
    Replies: 8
    Last Post: 23rd June 2009, 09:31

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.