PDA

View Full Version : QTreeWidget with different icon sizes



aguayro
11th January 2013, 22:01
I'm trying to set different icon size for top level items of QTreeWidget. I think the way is custom QItemDelegate, but i'm not sure how to do it (delegates are a bit confusing to me). I tryed to subclass "sizeHint()", but it only affects to the item size, not to icon size:



QSize treeSysDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const {
QSettings skSets(QString("Skin/%1/Skin.ini").arg(CurrSkin), QSettings::IniFormat);

if ( index.data(Qt::UserRole).toString() == "TopLevel1") {
return QSize(skSets.value("SystemsTree/HIconSize").toInt(), skSets.value("SystemsTree/HIconSize").toInt());
} else {
return QSize(skSets.value("SystemsTree/IconSize").toInt(), skSets.value("SystemsTree/IconSize").toInt());
}
}


How can i apply the sizehint to the icon?


I've noticed that the second arg ofsizeHint() is a QModelIndex, not sure if i must do a cast to QTreeWidget or something....



Hope anybody can help me.
Thanks in advance.