How to add an icon to my QListWidget? This should work fine (I am loading the icon from the resource file):
ui->listWidget->addItem(new QListWidgetItem(QIcon(":/res/icon"), ""));
EDIT
In the screenshot, I see that your problem is that there is some space above the icon corresponding to the empty line. You can crack this behavior by setting the font size of the list widget element to very small.
QListWidgetItem *newItem = new QListWidgetItem; QFont f; f.setPointSize(1); // It cannot be 0 newItem->setText(""); newItem->setIcon(QIcon(":/res/icon")); newItem->setFont(f); ui->listWidget->addItem(newItem);
This will do the trick. However, you can also use the setItemWidget function and use your custom widget or use the QListView and delegate.
source share