I have a QListWidget instance in the middle of my application. I want to populate it with some dynamically created QImage.

After reading the manual I have understand that i have to pass through a QIcon object. But.. How can I create a QIcon from a QImage?

I've seen an example, for instance

/Developer/Examples/Qt/itemviews/stardelegate

but it is not very useful, and around the internet I haven't found any suitable snippet.

有帮助吗?

解决方案

QListWidgetItem *item = new QListWidgetItem("something", listWidget);
itemitem->setData(Qt::DecorationRole, QPixmap::fromImage(image));
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top