Results 1 to 4 of 4

Thread: how to use QTreeView with Database model

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2006
    Location
    Erlangen, Germany
    Posts
    58
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to use QTreeView with Database model

    i understand that i will have to structure my data in a way that it makes sense in a tree.
    The data came in the form of
    01|NULL|NULL|Text
    01|01|NULL|Text
    01|01|01|Text
    01|01|02|Text

    so it makes sense to show it in a Tree but i doubt that if i send a tablemodel with this data to the QTreeView Object it will be able to work with that.
    Do i need to build a nested set or do i need to have a parent id in some column or how else do i need to prepare my data to give it to the tree?


    btw: what i meant with the QDir was the QDirModel which is always used to explain the QTreeView, as in http://doc.trolltech.com/4.0/qtreeview.html
    and no i don't want to use this i hope to be able to use a QSqlQueryModel or something like that.

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

    Default Re: how to use QTreeView with Database model

    You should be able to do this quickly using a two layered model. Lower layer should be QSqlTableModel or QSqlQueryModel and on top of that you'd have to implement a proxy model which will map indexes from the sql model to a tree structure (see docs for the proxy model for details).

Similar Threads

  1. Replies: 4
    Last Post: 6th February 2009, 19:18
  2. QTreeView and QAbstractItem Model.
    By Terabyte in forum Qt Programming
    Replies: 1
    Last Post: 13th January 2009, 13:18
  3. QTreeView restore Expanded node after reload model
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 26th May 2008, 17:42
  4. using QTreeView with a Database model
    By darksaga in forum Qt Programming
    Replies: 1
    Last Post: 17th January 2007, 23:29
  5. Modify model data in QTreeView
    By YuriyRusinov in forum Qt Programming
    Replies: 6
    Last Post: 26th October 2006, 17:28

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
  •  
Qt is a trademark of The Qt Company.