Reputation: 40335
I have a dialog set up like this:
Every components' properties are set to their defaults aside from the captions. I want the row containing label_3
to be the same height as the other three rows (and that bottom row to be expanded to take up the remaining space, as shown, to be clear). The problem is the checkbox isn't the same height as the text boxes, so the row has a different height. According to Designer, in the image above label_1
and friends have height 20, and label_3
has height 13. None of the following attempts worked quite right:
layoutRowStretch
property of the QGridLayout
has no effect.Setting the height to match one of the other label heights in the constructor, e.g.:
ui->label_3->setFixedHeight(ui->label_2->height());
Yields incorrect results:
Debugging shows that label_2->height()
in the constructor is 30, not 20 as reported in designer, and so label_3
's row ends up too large. Presumably this is because the dialog hasn't been displayed yet at that point and so the components have not been laid out.
I'm out of ideas. What's the cleanest way to do this that also does not involve hard coding sizes?
A Qt5 project for the example above is here.
Upvotes: 4
Views: 209
Reputation: 3996
I don't see any clean way to do this without manually setting the size.
However, from what I just tried in Qt5.5 the minimumSizeHint of the QLineEdit is set before being painted (with the default size you see in QtDesigner), so I was able to set the minimum-size of the QCheckBox in the Dialog constructor.
ui->checkBox->setMinimumHeight(ui->lineEdit->minimumSizeHint().height());
This gets wrong if I manually set a minimumHeight on the QLineEdit, as the minimumSizeHint is not changed, but using a max of the two is working :
ui->checkBox->setMinimumHeight(qMax(ui->lineEdit->minimumSizeHint().height(),
ui->lineEdit->minimumSize().height()));
Edit: in case of an OS-theme where a checkbox would have a greater height than the line-edit, you could use the max of both minimumSizeHint().height()
and set it as minimum-height on both widgets.
Upvotes: 1