PDA

View Full Version : QSpacerItem doesn't respect the minimum width of the qcombobox



PinTxO
27th October 2015, 11:57
Hi everyone.

I have the next problem. In runtime I create a QWidget with a QHBoxLayout layout and from the left to the right, I create a QLabel, a QSpacerItem, a QComboBox and a QPushButton. The idea is putting the label on the left and all the rest to the right. I put a minimum width to the combo but the spaceritem doesn't respect it doing it smaller than I want. Why?

The QSpacerItem:
auto headerSpacer = new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
The minimum width of the combo:
comboDevices->setMinimumWidth(500);

anda_skoa
27th October 2015, 12:24
Have you tried with a non-zero size?

Btw, if you are doing that in code, then calling QBoxLayout::addStretch() would be less code.

Cheers,
_

PinTxO
27th October 2015, 14:21
It as my fault. Ten lines of code below I had
comboDevices->setMinimumWidth(175);:(:(

Anyway thanks for the addStretch function, I didn't know it.