Results 1 to 4 of 4

Thread: Tree widget sorting

  1. #1
    Join Date
    Feb 2008
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Tree widget sorting

    I want to sort the tree widget based on the user data not the text displayed in the tree widget. How can i do this? MFC has the function SetItemData for the controls where we can store the user data in the nodes. How can i achieve this in QT. For example I want to display the names but it has to be sorted on age corresponding to name (which is user data).

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Tree widget sorting

    Hi, you can reimplement QTreeWidgetItem::operator<() to your like.
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    ganeshshenoy (11th February 2008)

  4. #3
    Join Date
    Feb 2008
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Tree widget sorting

    How can i store the user data in QTreewidgetitem?

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Tree widget sorting

    See QTreeWidgetItem::setData():
    Qt Code:
    1. item->setData(column, Qt::UserRole, data);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

Similar Threads

  1. rich text in tree widget
    By magland in forum Qt Programming
    Replies: 19
    Last Post: 12th March 2009, 13:07
  2. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  3. QTreeModel Items to a Widget
    By baray98 in forum Qt Programming
    Replies: 11
    Last Post: 30th December 2007, 09:32
  4. Drag from tree widget
    By EricF in forum Qt Programming
    Replies: 9
    Last Post: 17th December 2007, 23:09
  5. Sorting Tree items based on database properties
    By jnk5y in forum Qt Programming
    Replies: 3
    Last Post: 13th April 2006, 19:44

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.