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

2.5k Views Asked by At

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

There are 2 best solutions below

4
Serhiy Kulish On

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();
0
eyllanesc On

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());