Details
-
Bug
-
Resolution: Out of scope
-
P2: Important
-
4.6.2
-
None
-
32-bit Linux and Windows, Qt 4.6.2
Description
A radio button placed in the right column of a QFormLayout without a label in the left column is ignored in sizing the right column.
In the example below the size of the left group box grows to accommodate the radio button and the right group box does not; falling back on the line edit's sizeHint() and truncating the right hand end of the radio button label. The radio button size policy is Minimum but its sizeHint() seems to be ignored.
Expected that the field column would be sized to its content regardless of the presence of a label in the label column.
Code of similar structure is generated by Designer when a widget is placed without a label.
main.cpp
#include <QtGui> #include <QDebug> int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget *window = new QWidget(); // Left group box, each control has a label and group box // scales to size of radio button label. QGroupBox *leftGroupBox = new QGroupBox("Correct", window); QFormLayout *layoutL = new QFormLayout(leftGroupBox); leftGroupBox->setLayout(layoutL); QLineEdit *editL = new QLineEdit(window); layoutL->addRow("Label 1", editL); QRadioButton *radioL = new QRadioButton("Radio with long label", window); layoutL->addRow("Label 2", radioL); // Right group box, radio button does not have a label and group box // does not size to radio button label. QGroupBox *rightGroupBox = new QGroupBox("Incorrect?", window); QFormLayout *layoutR = new QFormLayout(rightGroupBox); rightGroupBox->setLayout(layoutR); QLineEdit *editR = new QLineEdit(window); layoutR->addRow("Label 1", editR); QRadioButton *radioR = new QRadioButton("Radio with long label", window); layoutR->setWidget(1, QFormLayout::FieldRole, radioR); QHBoxLayout *layout = new QHBoxLayout(window); layout->addWidget(leftGroupBox); layout->addWidget(rightGroupBox); window->setLayout(layout); window->show(); qDebug() << "Left group"; qDebug() << "Edit and radio sizeHint()" << editL->sizeHint() << radioL->sizeHint(); qDebug() << "Edit width" << editL->width(); qDebug() << "Right group"; qDebug() << "Edit and radio sizeHint()" << editR->sizeHint() << radioR->sizeHint(); qDebug() << "Edit width" << editR->width(); int ret = app.exec(); delete window; return ret; }
Output:
Left group Edit and radio sizeHint() QSize(110, 21) QSize(152, 20) Edit width 152 Right group Edit and radio sizeHint() QSize(110, 21) QSize(152, 20) Edit width 110