Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. increase size of the images in QComboBox

increase size of the images in QComboBox

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 630 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • AmrCoderA Offline
    AmrCoderA Offline
    AmrCoder
    wrote on last edited by AmrCoder
    #1

    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:
    .h

    class ComboView : public QListView
    {
    public:
        ComboView();
        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);
                o.decorationSize.setWidth(o.rect.width());
                o.decorationSize.setHeight(40);
                auto style =  o.widget ? o.widget->style() : QApplication::style();
                style->drawControl(QStyle::CE_ItemViewItem, &o, painter, o.widget);
            }
        };
    };
    

    .cpp

    ComboView::ComboView()
    {
        this->setSpacing(5);
        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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Which size are your images ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved