Important: Please read the Qt Code of Conduct -

increase size of the images in QComboBox

  • Hello,
    I want to create a simple combo box from images only and leave some space between images after some searches I found this code which using a class that inherits from QListView this my code:

    class ComboView : public QListView
        struct Delegate: public QStyledItemDelegate {
            Delegate(QObject* parent = nullptr) : QStyledItemDelegate(parent) {
            void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
                auto o = option;
                initStyleOption(&o, index);
                auto style =  o.widget ? o.widget->style() : QApplication::style();
                style->drawControl(QStyle::CE_ItemViewItem, &o, painter, o.widget);


        this->setItemDelegate(new Delegate);

    i use it before i add the items to my combo box

        ui->comboBox->setView(new ComboView);
        ui->comboBox->addItem(QIcon(":/logos/files/bing.png"), "");
        ui->comboBox->addItem(QIcon(":/logos/files/yahoo.png"), "");

    this make my icons which I add to the combo box shown in the center and no text at all, the problem is that the image in the combo box is not showing completely even after I leave some space in the constructor of the ComboView class it shows the missing part is from the top and the bottom
    so how can the icon fit in its item place?

  • Lifetime Qt Champion


    Which size are your images ?

Log in to reply