Jason C
Jason C

Reputation: 40335

Consistent row sizes in a QGridLayout

I have a dialog set up like this:

enter image description here

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:

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

Answers (1)

ymoreau
ymoreau

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

Related Questions