Results 1 to 4 of 4

Thread: How to sort columns by "icon"?

  1. #1
    Join Date
    Apr 2008
    Posts
    39
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to sort columns by "icon"?

    Hi there.

    I have a little problem to solve for my current project UltraStar Manager.

    Sorting in a QTreeWidget works fine as long as there is Text to sort. But how can I enable correct sorting for columns where only Icons appear?

    These icons are "ticks" and "crosses". I would like to have "tick > cross" If you know what I mean...

    So long

  2. #2
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to sort columns by "icon"?

    i am not sure about this..but did you try QIconEngineV2::read....http://doc.trolltech.com/4.4/qiconenginev2.html#read

  3. #3
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to sort columns by "icon"?

    When you create the QTreeWidgetItem for the items you want to sort, you could assign a data value to them and sort on that data value.

    Qt Code:
    1. treeWidgetItem = new QTreeWidgetItem( parent );
    2. treeWidgetItem->setData( column, Qt::DisplayRole, QVariant( tickValue ) );
    To copy to clipboard, switch view to plain text mode 

    As for sorting, override operator<() and you can do something like this.

    Qt Code:
    1. bool YourClass::operator<( const QTreeWidgetItem& item ) const
    2. {
    3. bool bReturn = false;
    4.  
    5. switch ( this->column() )
    6. {
    7. case ICON_COLUMN:
    8. if ( this->data( ICON_COLUMN, Qt::DisplayRole ).toUInt() < item.data( ICON_COLUMN, Qt::DisplayRole ).toUInt() )
    9. bReturn = true;
    10. break;
    11. default:
    12. bReturn = QTreeWidgetItem::operator <( item );
    13. }
    14.  
    15. return bReturn;
    16. }
    To copy to clipboard, switch view to plain text mode 

    I've used this with QTableWidgetItems with much success so it should translate to QTreeWidgetItems.

  4. #4
    Join Date
    Apr 2008
    Posts
    39
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to sort columns by "icon"?

    Thanks! I'll try it.

    Edit: But I don't want to show any text or so. Maybe I can use the UserRole to store my "sort data"

    2nd Edit: It worked very well! Thank you again.
    Last edited by youkai; 31st July 2008 at 20:58.

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.