+ Reply to Thread
Results 1 to 7 of 7

Thread: how to display QSqlQueryModel in QTreeView

  1. #1
    Join Date
    Nov 2006
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default how to display QSqlQueryModel in QTreeView

    Result of my sql query is hold in QSqlQueryModel; and i simply call
    mTreeView->setModel(qsqlquerymodel) to view results in treeview.
    TreeView displays my table; but it is not structured (there is no node or hiyerarchical structure in view.)
    I have looked around forum and understood that I have to subclass QAbstractProxyModel, and override its pure virtual methods. But i have no clue what to write in its methods.

    I will be grateful for any clue about how to write a proxy to have a structured display in QTreeView using QSqlQueryModel.

    Thanx in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,317
    Thanks
    3
    Thanked 4,999 Times in 4,779 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: how to display QSqlQueryModel in QTreeView

    We have no clue what to write in its methods as well. QSqlQuery returns a table, not a tree so don't make us guess how to convert any table into any tree. In other words: provide some details.
    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.


  3. #3
    Join Date
    Nov 2006
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to display QSqlQueryModel in QTreeView

    result that returned by my QsSlquery is :
    Qt Code:
    1. teamId studentId lectureId
    2. --------- ----------- ----------
    3. team1 student1 lecture1
    4. team1 student1 lecture3
    5. team1 student2 lecture1
    6. team2 student1 lecture3
    7. team2 student1 lecture4
    To copy to clipboard, switch view to plain text mode 

    i assign my QSqlQuery to QSqlQueryModel using setQuery,
    and then assign QSqlQueryModel to QTreeView using setModel.
    As a result tree view displays my table without hiyerarchical structure just like the table above.

    But I am trying to get a display like this:
    Qt Code:
    1. -team1
    2. -student1
    3. -lecture1
    4. -lecture3
    5. -student2
    6. -lecture1
    7. -team2
    8. -student1
    9. -lecture3
    10. -lecture4
    To copy to clipboard, switch view to plain text mode 
    As i learned i have to use QAbstractProxyModel; but i do not know how to do it.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,317
    Thanks
    3
    Thanked 4,999 Times in 4,779 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: how to display QSqlQueryModel in QTreeView

    You have to provide a mapping between a flat and hierarchical structure by reimplementing QAbstractProxyModel::mapToSource() and QAbstractProxyModel::mapFromSource().
    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
    Nov 2006
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to display QSqlQueryModel in QTreeView

    am i supposed to loop on QSqlquery and build my own tree structure in these methods??

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,317
    Thanks
    3
    Thanked 4,999 Times in 4,779 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: how to display QSqlQueryModel in QTreeView

    No. Based on a given source model index you have to be able to calculate the hierarchy (parent) and position (row, column) in the destination model.

    If this all sounds too complicated for you, you can forget about query and proxy models and based on QSqlQuery and QStandardItemModel build a new model and copy the data to it from the query.
    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.


  7. The following user says thank you to wysota for this useful post:

    mandal (2nd September 2009)

  8. #7
    Join Date
    Nov 2006
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to display QSqlQueryModel in QTreeView

    i will try subcllassing proxymode firstl..
    Thanks for your help..

+ Reply to Thread

Similar Threads

  1. Process the display data before displaying in QTreeView
    By babu198649 in forum Qt Programming
    Replies: 5
    Last Post: 23rd June 2009, 06:21
  2. QSqlQueryModel -> QTreeView
    By smrtak in forum Qt Programming
    Replies: 3
    Last Post: 24th August 2008, 19:12
  3. Display only PNG image on desktop
    By durbrak in forum Qt Programming
    Replies: 32
    Last Post: 15th March 2008, 22:55
  4. QTreeView help
    By bepaald in forum Qt Programming
    Replies: 1
    Last Post: 15th August 2007, 22:22
  5. Can't change the text display of a QTreeview item.
    By johnny_sparx in forum Qt Programming
    Replies: 3
    Last Post: 2nd June 2006, 02:03

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