Results 1 to 4 of 4

Thread: Sorting Tree items based on database properties

  1. #1
    Join Date
    Feb 2006
    Posts
    21
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Sorting Tree items based on database properties

    Hello all,

    Lets suppose I have a database table called people filled with names and addresses. I fill a qTreeWidget by doing

    Qt Code:
    1. QTreeWidgetItem* peopleNode;
    2. treeWidget->addTopLevelItem( peopleNode );
    3.  
    4. query.exec( "SELECT first_name FROM people;" );
    5. while( query.next() ) {
    6. QTreeWidgetItem* PeopleList = new QTreeWidgetItem(peopleNode);
    7. PeopleList->setText( 0, query.value(0).toString() );
    8. }
    To copy to clipboard, switch view to plain text mode 

    I would like to be able to right click on the peopleNode or items within and have a "sort by" menu which would list all the table columns and then sort the Node by that column.

    Can anyone see a way of doing this

  2. #2
    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: Sorting Tree items based on database properties

    You need a sort-filter proxy model and a context menu for the view.

  3. #3
    Join Date
    Feb 2006
    Posts
    21
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sorting Tree items based on database properties

    I'm sorry but I am not familiar with sort-filter proxy model. Could you explain it in further detail?

  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: Sorting Tree items based on database properties

    Take a look at QSortFilterProxyModel.

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.