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. QT I want to increase the size of comboBox Down list not the drop- Down icon ?
Forum Updated to NodeBB v4.3 + New Features

QT I want to increase the size of comboBox Down list not the drop- Down icon ?

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 4 Posters 8.1k 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi
    You can set size via the model. (pr item)

    #include <QtGui>
    #include <QApplication>
    #include <QComboBox>

    int main(int argc, char **argv)
    {
    QApplication app(argc, argv);
    QComboBox cb;
    cb.addItems(QStringList() << "a" << "b" << "c" << "d");
    cb.model()->setData(cb.model()->index(0, 0), QSize(100, 100), Qt::SizeHintRole);
    cb.show();
    return app.exec();
    }

    You can also use a stylesheet.

    A 1 Reply Last reply
    3
    • mrjjM mrjj

      Hi
      You can set size via the model. (pr item)

      #include <QtGui>
      #include <QApplication>
      #include <QComboBox>

      int main(int argc, char **argv)
      {
      QApplication app(argc, argv);
      QComboBox cb;
      cb.addItems(QStringList() << "a" << "b" << "c" << "d");
      cb.model()->setData(cb.model()->index(0, 0), QSize(100, 100), Qt::SizeHintRole);
      cb.show();
      return app.exec();
      }

      You can also use a stylesheet.

      A Offline
      A Offline
      amarism
      wrote on last edited by amarism
      #3

      @mrjj when i use one code :-

      ui->comboBox->model()->setData(ui->comboBox->model()->index(0, 0), QSize(100, 100), Qt::SizeHintRole);
      

      this one just increase the size icon index size not the down list width.
      Also I dont want to show the icon inside the drop list.

      mrjjM 1 Reply Last reply
      0
      • A amarism

        @mrjj when i use one code :-

        ui->comboBox->model()->setData(ui->comboBox->model()->index(0, 0), QSize(100, 100), Qt::SizeHintRole);
        

        this one just increase the size icon index size not the down list width.
        Also I dont want to show the icon inside the drop list.

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #4

        @amarism
        Hi
        It sets the Items Height.
        Just make all items bigger and dropdown also be bigger.
        Sample just sets item 0,0. you need set on all items.

        A 1 Reply Last reply
        0
        • mrjjM mrjj

          @amarism
          Hi
          It sets the Items Height.
          Just make all items bigger and dropdown also be bigger.
          Sample just sets item 0,0. you need set on all items.

          A Offline
          A Offline
          amarism
          wrote on last edited by amarism
          #5

          @mrjj said in QT I want to increase the size of comboBox Down list not the drop- Down icon ?:

          Just make all items bigger and dropdown also be bigger.

          Sorry i am not getting this thing. item bigger and dropdown bigger. But I want only item width bigger

          mrjjM 1 Reply Last reply
          0
          • A amarism

            @mrjj said in QT I want to increase the size of comboBox Down list not the drop- Down icon ?:

            Just make all items bigger and dropdown also be bigger.

            Sorry i am not getting this thing. item bigger and dropdown bigger. But I want only item width bigger

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @amarism
            Just adjust to what u want
            QSize(100, 100) is the size. 100 width, 100 height

            But the width of the drop-down is the width of the combo itself
            alt text

            A 1 Reply Last reply
            0
            • mrjjM mrjj

              @amarism
              Just adjust to what u want
              QSize(100, 100) is the size. 100 width, 100 height

              But the width of the drop-down is the width of the combo itself
              alt text

              A Offline
              A Offline
              amarism
              wrote on last edited by
              #7

              @mrjj I don't want to increase the size of header combo box . Becaue i am using combobox as a button in my ui viewer. So, I can't set button size this much. I want the combo Box like this 0_1536056909807_DDfinal.png

              mrjjM 1 Reply Last reply
              0
              • A amarism

                @mrjj I don't want to increase the size of header combo box . Becaue i am using combobox as a button in my ui viewer. So, I can't set button size this much. I want the combo Box like this 0_1536056909807_DDfinal.png

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #8

                @amarism
                ok.
                you need to subclass for that i think.
                https://forum.qt.io/topic/30405/how-to-change-qcombobox-popup-width

                Alternatively, you canuse toolbutton and QMenu.

                A 1 Reply Last reply
                0
                • mrjjM mrjj

                  @amarism
                  ok.
                  you need to subclass for that i think.
                  https://forum.qt.io/topic/30405/how-to-change-qcombobox-popup-width

                  Alternatively, you canuse toolbutton and QMenu.

                  A Offline
                  A Offline
                  amarism
                  wrote on last edited by
                  #9

                  @mrjj So i need to create QTableWidget inside the comboBox or any other method to do this

                  mrjjM 1 Reply Last reply
                  1
                  • A amarism

                    @mrjj So i need to create QTableWidget inside the comboBox or any other method to do this

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @amarism
                    I dont know what u mean.
                    Link talks about overriding showPopup to alter size.
                    That should do it.

                    A 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      @amarism
                      I dont know what u mean.
                      Link talks about overriding showPopup to alter size.
                      That should do it.

                      A Offline
                      A Offline
                      amarism
                      wrote on last edited by
                      #11

                      @mrjj Still i am not getting any proper solution for this question

                      jsulmJ 1 Reply Last reply
                      0
                      • A amarism

                        @mrjj Still i am not getting any proper solution for this question

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        @amarism Did you try what @mrjj suggested?

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        A 1 Reply Last reply
                        1
                        • jsulmJ jsulm

                          @amarism Did you try what @mrjj suggested?

                          A Offline
                          A Offline
                          amarism
                          wrote on last edited by
                          #13

                          @jsulm yup but still this one not working

                          mrjjM 1 Reply Last reply
                          0
                          • A amarism

                            @jsulm yup but still this one not working

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by mrjj
                            #14

                            @amarism
                            In what way did it not work for you ?
                            Seems to work as expected.
                            alt text

                            class WideComboBox : public QComboBox
                            {
                                Q_OBJECT
                            public:
                                explicit WideComboBox(QWidget *parent = nullptr) : QComboBox(parent) {};
                                ~WideComboBox() {}
                            public:
                                void showPopup() {
                                    this->view()->setMinimumWidth(this->view()->sizeHintForColumn(0));
                                    QComboBox::showPopup();
                                }
                            };
                            
                            

                            setting it to 400 ;)

                            alt text

                            A 1 Reply Last reply
                            5
                            • J.HilkJ Offline
                              J.HilkJ Offline
                              J.Hilk
                              Moderators
                              wrote on last edited by
                              #15

                              Additionally to what @mrjj wrote, you should also be able to set the size of the view via a StyleSheet, a viable option if you don't plan to vary the size all to often

                              ui->comboBox->setStyleSheet("QComboBox QAbstractItemView {min-width: 400px;}"),


                              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                              Q: What's that?
                              A: It's blue light.
                              Q: What does it do?
                              A: It turns blue.

                              A 2 Replies Last reply
                              2
                              • mrjjM mrjj

                                @amarism
                                In what way did it not work for you ?
                                Seems to work as expected.
                                alt text

                                class WideComboBox : public QComboBox
                                {
                                    Q_OBJECT
                                public:
                                    explicit WideComboBox(QWidget *parent = nullptr) : QComboBox(parent) {};
                                    ~WideComboBox() {}
                                public:
                                    void showPopup() {
                                        this->view()->setMinimumWidth(this->view()->sizeHintForColumn(0));
                                        QComboBox::showPopup();
                                    }
                                };
                                
                                

                                setting it to 400 ;)

                                alt text

                                A Offline
                                A Offline
                                amarism
                                wrote on last edited by amarism
                                #16

                                can i add the vertical spacing between the rows

                                1 Reply Last reply
                                0
                                • J.HilkJ J.Hilk

                                  Additionally to what @mrjj wrote, you should also be able to set the size of the view via a StyleSheet, a viable option if you don't plan to vary the size all to often

                                  ui->comboBox->setStyleSheet("QComboBox QAbstractItemView {min-width: 400px;}"),

                                  A Offline
                                  A Offline
                                  amarism
                                  wrote on last edited by
                                  #17

                                  @J.Hilk Thanku @J-Hilk . Now its working for me

                                  1 Reply Last reply
                                  0
                                  • J.HilkJ J.Hilk

                                    Additionally to what @mrjj wrote, you should also be able to set the size of the view via a StyleSheet, a viable option if you don't plan to vary the size all to often

                                    ui->comboBox->setStyleSheet("QComboBox QAbstractItemView {min-width: 400px;}"),

                                    A Offline
                                    A Offline
                                    amarism
                                    wrote on last edited by
                                    #18

                                    @J.Hilk One more problem comes here, I am added a icon for combo box . And it will showing inside the dropdown popup. can i hide from icom from dropdown button

                                    J.HilkJ 1 Reply Last reply
                                    0
                                    • A amarism

                                      @J.Hilk One more problem comes here, I am added a icon for combo box . And it will showing inside the dropdown popup. can i hide from icom from dropdown button

                                      J.HilkJ Offline
                                      J.HilkJ Offline
                                      J.Hilk
                                      Moderators
                                      wrote on last edited by
                                      #19

                                      @amarism I don't think you can do that via the StyleSheet. My guess would be to subclass QComboBox and override the paintEvent and ignore the Qt::DecorationRole !?


                                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                      Q: What's that?
                                      A: It's blue light.
                                      Q: What does it do?
                                      A: It turns blue.

                                      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