How to set image for string?

I want to add text (at the beginning of the line) and an image at the end of the line.

I can set the text, but how to set the image at the end of the line element in QTreeWidgetItem?

+5
source share
1 answer

Just set, for example, two columns in a QTreeWidget, and then set the text in the first and the icon in the second:

QTreeWidgetItem *newItem = new QTreeWidgetItem;
newItem->setText(0, "Something");
newItem->setIcon(1, QIcon("Path to your icon"));

myTreeWidget->addTopLeveItem(newItem);

Or add a settings icon, which you can simply set in the foreground:

newItem->setForeground(QBrush(QPixmap("Path to your image")));

what could be better for your problem.

+9
source

All Articles