Unsolved How to add multiple icons to TreeItems of QAbstractTreeModel
-
This is my current code i am only able to insert only one icon to the treeItem.
How can i add both the icons to the treeItem
QVariant TreeModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); TreeItem *item = getItem(index); if (item) { switch (role) { case Qt::DisplayRole: case Qt::EditRole: return QString::fromStdString(item->data().GetName()); break; case Qt::DecorationRole: { Container *cont = item->GetContainer(); if (cont->GetGeometry()->isValid()) { QString qstrIconName = cont->GetGeometry()->GetType().c_str(); QString qstrIconPath = QCoreApplication::applicationDirPath(); QPixmap pixmap; QIcon icon; qstrIconPath = qstrIconPath + "/Icons/" + qstrIconName + ".png"; pixmap.load(qstrIconPath); icon.addPixmap(pixmap, QIcon::Normal, QIcon::On); return icon; } // Function returns from here since we have returned the icon // How can i add next icon to the same tree item int numberOfFunctions = cont->getNumberOfFunctions(); if (numberOfFunctions > 0) { QString qstrIconName = "FUNCTION"; QString qstrIconPath = QCoreApplication::applicationDirPath(); QPixmap pixmap; QIcon icon; qstrIconPath = qstrIconPath + "/Icons/" + qstrIconName + ".png"; pixmap.load(qstrIconPath); icon.addPixmap(pixmap, QIcon::Normal, QIcon::On); return icon; } break; } } return QVariant(); } }
-
@summit
I assume thatDecorationRole
only allows for one icon? I don't know how generically you would expect multiple icons to be accepted/displayed? -
@JonB Yes lot of time i would expect multiple icons to be displayed , what are the other ways i can achieve this ?
-
@summit
I will be silent after this, to allow another who knows better than I to help you, but I would assume you must look atQStyledItemDelegate
as your way of displaying non-standard things like multiple icons, instead of going viaDecoration
role. -
- Add one column for every icon.
- Create a big size icon that contains several icons in a row.
- Write custom item delegate, draw in your own way.