0

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?!

Subaru Tashiro
  • 2,166
  • 1
  • 14
  • 29

1 Answers1

0

I found this SO post where in this most voted answer I can read that setting a size policy on top-level windows does not work. Maybe if you used setLayout() method of your dialog and used setFixedHeight() on your main layout in your dialog, then it would work.

Alternatively you could override resizeEvent() of your dialog and disable all height changes manually ...

Community
  • 1
  • 1
jcxz
  • 1,226
  • 2
  • 12
  • 25
  • i'm not setting the sizepolicy, i'm setting the fixedHeight. Take a look at my code. Sorry but I might downvote your answer. – Subaru Tashiro Mar 25 '13 at 11:04
  • Update: after checking the documentation, there is no setFixedHeight() method for QHBoxLayouts. Gonna downvote your answer. Edit: Whoops, looks like I can't. Oh well. – Subaru Tashiro Mar 25 '13 at 11:15