QLineEdit doesn't stretch to occupy full space in the layout
I have a an application which uses a
QGridLayoutto display/edit some text. The following piece of is what I use to construct and add the widget into the layout.
// ... QLineEdit *edit = new QLineEdit; edit->setReadOnly(true); edit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum); edit->setAlignment(Qt::AlignCenter); // ... QGridLayout *layout = new QGridLayout; layout->addWidget(promptLabel, 0, 0, 1, 1, Qt::AlignLeft); layout->addWidget(new QLabel(""), 0, 1, 1, 1); layout->addWidget(edit, 0, 2, 1, 2, Qt::AlignLeft); layout->addWidget(new QLabel(""), 0, 4, 1, 1); layout->addWidget(selector, 0, 5, 1, 1, Qt::AlignLeft); // ...
I have set the horizontal stretch factor to 1 using the
setHorizontalStretchfunction, but it didn't help. Note that this layout is part of another large layout with a few more widgets and my main widget's layout is governed via layouts (i.e., no fixed size provided).
Any help would be much appreciated.