QPixmap(image) in QComboBox
-
The documentation on QComboBox says "Comboboxes can contain pixmaps as well as strings". I suppose this doesn't refer to icons.
However, I can't see any member function to do that, at least not in Qt 5. Is the documentation outdated? Is there any way to do this ?
Meanwhile I'll experiment with stylesheets. -
Hi,
You can use this overload of addItem to which you can pass an icon.
Is that what you are looking for ?
-
You can set the decoration role of your items with the pixmap you want to show.
Or depending on how you would like to render your images, you can also use a custom delegate that does what you want.
-
@SGaist said in QPixmap(image) in QComboBox:
You can set the decoration role of your items with the pixmap you want to show.
I tried this:
QPixmap p1(":/res/grad0-120.jpeg"); QPixmap p2(":/res/grad0-240.jpeg"); QPixmap p3(":/res/grad240-360.jpeg"); ui->combo->setItemData(0,p1,Qt::DecorationRole); ui->combo->setItemData(1,p2,Qt::DecorationRole); ui->combo->setItemData(2,p3,Qt::DecorationRole);
and got this:
As you can see, the pixmaps display fine in the dropdown, but are very small in the top cell. Any idea how to solve this ? I have some CSS applied to the combo box, but it's not causing any problem. Also it appears there is an annoying 5px white strip on the left side of the items.
-
What OS are you on ?
-