Setting a ComboBox's width to fixed in a QHBoxLayout
-
wrote on 8 Nov 2016, 16:01 last edited by MaxDevI 11 Aug 2016, 16:59
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
-
Hmm
You can use
setMaximumWidth to set a max. -
wrote on 8 Nov 2016, 16:58 last edited by
I have tried it, it does not work
-
@MaxDevI
Hmm. Strange. It works here.
It stays 64 pixels. -
wrote on 8 Nov 2016, 17:43 last edited by
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...?
-
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. -
Hi,
IIRC, the size policy might help.
-
wrote on 8 Nov 2016, 23:40 last edited by
@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...
-
wrote on 8 Nov 2016, 23:49 last edited by
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/9