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.
treeWidgetItem
->setData
( column, Qt
::DisplayRole,
QVariant( tickValue
) );
treeWidgetItem = new QTreeWidgetItem( parent );
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.
bool YourClass::operator<( const QTreeWidgetItem& item ) const
{
bool bReturn = false;
switch ( this->column() )
{
case ICON_COLUMN:
if ( this->data( ICON_COLUMN, Qt::DisplayRole ).toUInt() < item.data( ICON_COLUMN, Qt::DisplayRole ).toUInt() )
bReturn = true;
break;
default:
}
return bReturn;
}
bool YourClass::operator<( const QTreeWidgetItem& item ) const
{
bool bReturn = false;
switch ( this->column() )
{
case ICON_COLUMN:
if ( this->data( ICON_COLUMN, Qt::DisplayRole ).toUInt() < item.data( ICON_COLUMN, Qt::DisplayRole ).toUInt() )
bReturn = true;
break;
default:
bReturn = QTreeWidgetItem::operator <( item );
}
return bReturn;
}
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.
Bookmarks