Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6099013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:13:27+00:00 2026-05-23T13:13:27+00:00

How to make QComboBox as MultiSelect in QT ? There is no option of

  • 0

How to make QComboBox as MultiSelect in QT ?

There is no option of MultiSelect in Combox in QT ?

OR

Anybody can suggest me some diffrent control but look & feel should be like QCombobox only.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:13:28+00:00Added an answer on May 23, 2026 at 1:13 pm

    //This is the file named as CheckBoxList.h

    #ifndef CHECKBOXLIST_H
    #define CHECKBOXLIST_H
    
    #include <QtGui>
    
    class CheckBoxList: public QComboBox
    {
        Q_OBJECT;
    
    public:
        CheckBoxList(QWidget *widget = 0);
        virtual ~CheckBoxList();
        bool eventFilter(QObject *object, QEvent *event);
        virtual void paintEvent(QPaintEvent *);
        void SetDisplayText(QString text);
        QString GetDisplayText() const;
    
    private:
        QString m_DisplayText;
    };
    
    #endif // CHECKBOXLIST_H
    

    //This is the file named as CheckBoxList.cpp

    #include "CheckBoxList.h"
    #include <QtGui>
    
    // internal private delegate
    class CheckBoxListDelegate : public QItemDelegate
    {
    public:
    
        CheckBoxListDelegate(QObject *parent)
             : QItemDelegate(parent)
        {
            ;
        }
    
        void paint(QPainter *painter, const QStyleOptionViewItem &option,
                              const QModelIndex &index) const
        {
            //Get item data
            bool value = index.data(Qt::UserRole).toBool();
            QString text = index.data(Qt::DisplayRole).toString();
    
            // fill style options with item data
            const QStyle *style = QApplication::style();
            QStyleOptionButton opt;
            opt.state |= value ? QStyle::State_On : QStyle::State_Off;
            opt.state |= QStyle::State_Enabled;
            opt.text = text;
            opt.rect = option.rect;
    
            // draw item data as CheckBox
            style->drawControl(QStyle::CE_CheckBox,&opt,painter);
    //QMessageBox::information(0,"Info",text);
    
        }
    
            QWidget *createEditor(QWidget *parent,
             const QStyleOptionViewItem & option ,
             const QModelIndex & index ) const
        {
            // create check box as our editor
    
             QCheckBox *editor = new QCheckBox(parent);
    
             return editor;
        }
    
         void setEditorData(QWidget *editor,
                                             const QModelIndex &index) const
         {
    
             //set editor data
             QCheckBox *myEditor = static_cast<QCheckBox*>(editor);
             myEditor->setText(index.data(Qt::DisplayRole).toString());
             myEditor->setChecked(index.data(Qt::UserRole).toBool());
    
    //
         }
    
         void setModelData(QWidget *editor, QAbstractItemModel *model,
                                            const QModelIndex &index) const
         {
             //get the value from the editor (CheckBox)
             QCheckBox *myEditor = static_cast<QCheckBox*>(editor);
             bool value = myEditor->isChecked();
    
    
             //set model data
             QMap<int,QVariant> data;
             data.insert(Qt::DisplayRole,myEditor->text());
             data.insert(Qt::UserRole,value);
             model->setItemData(index,data);
    
         }
    
         void updateEditorGeometry(QWidget *editor,
             const QStyleOptionViewItem &option, const QModelIndex &index ) const
         {
    
             editor->setGeometry(option.rect);
    
    
         }
     };     
    //min-width:10em; 
         CheckBoxList::CheckBoxList(QWidget *widget )
         :QComboBox(widget),m_DisplayText(0)
         {
        // set delegate items view 
        view()->setItemDelegate(new CheckBoxListDelegate(this));
        //view()->setStyleSheet("  padding: 15px; ");
        // Enable editing on items view
        view()->setEditTriggers(QAbstractItemView::CurrentChanged);
    
        // set "CheckBoxList::eventFilter" as event filter for items view 
        view()->viewport()->installEventFilter(this);
    
    
        // it just cool to have it as defualt ;)
        view()->setAlternatingRowColors(true);
         }
    
    
    CheckBoxList::~CheckBoxList()
    {
        ;
    }
    bool CheckBoxList::eventFilter(QObject *object, QEvent *event)
    {
        // don't close items view after we release the mouse button
        // by simple eating MouseButtonRelease in viewport of items view
        if(event->type() == QEvent::MouseButtonRelease && object==view()->viewport()) 
        {
            return true;
        }
        return QComboBox::eventFilter(object,event);
    }
    void CheckBoxList::paintEvent(QPaintEvent *)
    {
        QStylePainter painter(this);
        painter.setPen(palette().color(QPalette::Text));
    
        // draw the combobox frame, focusrect and selected etc.
        QStyleOptionComboBox opt;
        initStyleOption(&opt);
    
        // if no display text been set , use "..." as default
        if(m_DisplayText.isNull())
            opt.currentText = "......";
        else
            opt.currentText = m_DisplayText;
        painter.drawComplexControl(QStyle::CC_ComboBox, opt);
    
        // draw the icon and text
        painter.drawControl(QStyle::CE_ComboBoxLabel, opt);
    
    }
    
    
    void CheckBoxList::SetDisplayText(QString text)
    {
        m_DisplayText = text;
    
    }
    
    QString CheckBoxList::GetDisplayText() const
    {
        return m_DisplayText;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may seem strange... but I'm wondering if there is anyway to make a
Can I make ComboBox from AjaxToolkit make call to server every time new letter
How can I make the comboBox available when the checkBox was uncheck (vice versa)
how can i make a TRibbonComboBox act like a TCombobox with Style of csDropDownList?
When I make selection in ComboBox, and then type some text in TextBox, I
How can I make a listbox dropdown like a combobox? Or is it possible
I want to make a ComboBox filled with all the colors from System.Drawing.Color But
I can't manage to make the contents of my combobox' dropdown list wrap properly.
How do I make a QVector (or some other container class) of a dynamic
How can you make a ComboBox where the user can select null ? If

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.