TreeView and an Icon
-
I have a TreeView made with QAbstractItemModel. Now i want to add an Icon to the left of the Text. I found QStyledItemDelegate for that, but at the moment i dont know how to do that. Its very hard for a Beginner like me to understand that MV Framework in that way. I only want to show an Icon on the leftside of each TreeItem.
Is it only possible to do that with the paint method in the QStyledItemDelegate? If yes, how?
-
@Fuel
Is it only possible to do that with the paint method in the QStyledItemDelegate? If yes, how?if you have use
QStandardItem
you can usesetIcon
to set the icon but then then the actual drawing is done usingdrawPixmap
. Something like this inpaint
:QIcon icon = index.data(Qt::DecorationRole).value<QIcon>(); QPixmap pixmap = icon.pixmap(QSize(24, 24)); painter->drawPixmap(rect(), pixmap);
-
Thats the Problem. I used an own Class for a TreeItem. Do i need to implement an Icon in to this Item Class?
-
If you inherited QStandardItem for your class, it should still be the same?