How to set Qdialog to have a fixed height as small as possible and an expending width in Qt Creator?

Viewed 1679

I have a Qdialog with a horizontal layout and a couple of elements. Now, I want the height to be fixed at its minimal possible size (while the width is still resizeable).

There are a couple of properties I can set, for example:

  • sizePolicy, minimumSize, maximumSize, baseSize, layoutSizeConstraint

I tried to understand how the values interact and a couple of combinations but none got me what I want.

For example, I can enter the smallest Height possible in maximumSize, in my case 178, and set the Vertical Policy in sizePolicy to Fixed. But then it is only fixed to a small range: I can still resize the dialog's height slightly to make it slightly smaller.

2 Answers

This type of tasks can not be done with Qt Designer, the minimum size if you use layouts is the sizeHint(), for example in your case the solution is:

dialog.setFixedHeight(dialog.sizeHint().height());

Try to set minimumSize.Height and maximumSize.Height with same values

or

Just set fixed height in code

Dialog dialog;
dialog.setFixedHeight(dialog.height());
dialog.exec();
Related