PDA

View Full Version : Expanding lineEdit in QHBoxLayout is not working properly in qt plugins



alizadeh91
27th January 2013, 16:02
HI,
I've created a qt plugin with comboBox and lineEdit and put them in QHBoxLayout in Qt5. when i set sizepolicy of lineEdit to expanding, it doesn't works properly. actually it expands itself a little:
8635

my code in plugin constructor is something like below:



comboBox = new QComboBox;
lineEditValue = new QLineEdit;

horizontalLayout = new QHBoxLayout(this);
horizontalLayout->setMargin(1);

comboBox->setSizePolicy(QSizePolicy::Preferred,QSizePolicy:: Fixed);
lineEditValue->setSizePolicy(QSizePolicy::Expanding,QSizePolicy:: Fixed);

horizontalLayout->addWidget(lineEditValue,0,Qt::AlignLeft);
horizontalLayout->addWidget(comboBox,0,Qt::AlignRight);

this->setLayout(horizontalLayout);

what i am missing?

alizadeh91
28th January 2013, 08:15
Any hint?! mybe i have to use ui file instead of creating comboBox and lineEdit in code? Can i create them in ui file inside of plugin?!

anda_skoa
29th January 2013, 13:28
Try this:
do not change the size policy of either widget, but use a stretch > 0 on the line edit



horizontalLayout->addWidget(lineEditValue, 1);


Cheers,
_

alizadeh91
30th January 2013, 08:12
Thanks but it didn't worked either!

Added after 11 minutes:

Maybe something is wrong when it is in a plugin?