Important: Please read the Qt Code of Conduct -

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.

  • Lifetime Qt Champion


    You can use this overload of addItem to which you can pass an icon.

    Is that what you are looking for ?

  • Nope, I want to fill the entire cell/item with a pixmap.

  • Lifetime Qt Champion

    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");

    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.

  • Lifetime Qt Champion

    What OS are you on ?

  • @SGaist
    Windows 7

    I managed to also do it differently, setting the images as icons to each combo element, and the doing some CSS adjustments, and


    It's far from perfect, but it's better:


Log in to reply