I recently moved to Qt5 and encountered a problem i'm not getting in Qt4.
I have a modal dialog that needs to have a fixed height but a resizeable width. For demonstration here's a stripped down version.
QDialog dialog;
QHBoxLayout hLayout;
QLineEdit lineEdit;
QPushButton button("Check Current Height");
hLayout.addWidget(&lineEdit);
hLayout.addWidget(&button);
dialog.setLayout(&hLayout);
dialog.setFixedHeight(dialog.sizeHint().height());
qDebug() << dialog.height()
<< dialog.sizeHint().height()
<< dialog.minimumHeight()
<< dialog.maximumHeight();
dialog.exec();
Even when i'm using setMinimumHeight & setMaximumHeight instead of setFixedHeight it's still resizeable.
in the above example all the stuff fed into qDebug is shown to be equal. If minimum and maximum height are equal, the dialog shouldn't be resizable. But here, It is.
It's worth mentioning here that without setFixedHeight the dialog is completely resizeable but with setFixedHeight the dialog is only resizable to a certain point.
Update: I've connected button
to a slot that outputs dialog
's minimumHeight
, maximumHeight
, sizeHint.height()
and current height
just like the qDebug()
above. And when I resize my dialog, sometimes it's current height exceeds it's maximum height. How is this possible?!