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. Setting a ComboBox's width to fixed in a QHBoxLayout
QtWS25 Last Chance

Setting a ComboBox's width to fixed in a QHBoxLayout

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 4.8k Views
  • 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.
  • M Offline
    M Offline
    MaxDevI
    wrote on last edited by MaxDevI
    #1

    I use setFixed function on a comboBox, then add it to a QHBoxLayout...the width of the combobox adjusts to fill the QHBoxLayout's extra space, but the height stays fixed as I want it to.

    I have tried using setMaximumWidth...layout->setStretchFactor...size policy to fixed...why is my comboBox stretching?

    How can I keep the combobox's width from adjusting? Thanks

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

      Hmm
      You can use
      setMaximumWidth to set a max.

      1 Reply Last reply
      1
      • M Offline
        M Offline
        MaxDevI
        wrote on last edited by
        #3

        I have tried it, it does not work

        mrjjM 1 Reply Last reply
        0
        • M MaxDevI

          I have tried it, it does not work

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

          @MaxDevI
          Hmm. Strange. It works here.

          It stays 64 pixels.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MaxDevI
            wrote on last edited by
            #5

            Yeah, this code seems to resize it someway somehow after the fact. I set it to size I want, then check it's size with ->size(), then add to layout, check size again, and it is still the size I set.

            I think this means it changes the size somewhere else in program after, but I do not know where.

            What I am looking for is a method to keep my comboBox's width throughout the rest of the program...why doesn't setFixedSize work...?

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              The layout controls the size. Its the same with setGeometry. It wont work when in layout.
              setFixedSize should also work. Its the same as setting equal values for both min/max.

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

                Hi,

                IIRC, the size policy might help.

                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
                • M Offline
                  M Offline
                  MaxDevI
                  wrote on last edited by
                  #8

                  @SGaist @mrjj SizePolicy and SetFixedSize did not work. I was able to get the original QComboBox less wide by setting

                  comboBox->setStyleSheet("QComboBox{margin-left: 80px;} QComboBox QAbstractItemView{margin-left:80 px;}");
                  

                  This makes this happen...I am beyond frustrated by this. What in the WORLD is causing this and why does Qt have so many areas where things just DON'T WORK.

                  The highlighting even works in the new version! The only thing I need to remove now is the extra blankspace that is the same length as the original box itself...

                  alt text

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    MaxDevI
                    wrote on last edited by
                    #9
                        comboBox->setMaximumWidth(20);
                        comboBox->setMinimumWidth(20);
                    
                        comboBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
                        comboBox->setFixedSize(20, 20);
                        (add comboBox to HBoxLayout here)
                        qDebug() << comboBox->size();
                    

                    This debug prints out 20,20 as the size...but my comboBox is definitely not 20, 20!!!!! How can this be happening!?!?!

                    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