Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize QDialog at a runtime

I have a QDialog subclass containing some options of my application. Some of the options are core, the other are advanced, so I decided to put them into separeted checkable QGroupBox. enter image description here
I want my dialog to shrink verticaly when the user checked off advanced options box, but I can't find the way to do it properly - the dialog size stays exactle the same enter image description here
I set dialog's size policy to Expanding, tried to call adjustSize() and tried to call resize() method - nothing helps. I can't resize programmaticaly dialog to be smaller then it's current size (it only can become larger). At the same time, it is possible to resize it manualy. enter image description here
Can anybody help me?

like image 835
Mikhail Zimka Avatar asked Jul 11 '14 08:07

Mikhail Zimka


People also ask

Does resizing qtablewidget increase qdialog size?

and resizing QTableWidget to rows and columns does not increase QDialog size, only increases QTableWidget size. i can't now tell about qDialog, but there is "resizeToContents" with the help of the widget.

How to change the size of dialog-box widget?

Other option is to select the corner of the Dialog-box widget and drag it for the required size. At runtime the size of the DIALOG-BOX widget remains as you have defined.

How do I change the ownership of a qdialog widget?

A dialog is always a top-level widget, but if it has a parent, its default location is centered on top of the parent's top-level widget (if it is not top-level itself). It will also share the parent's taskbar entry. Use the overload of the QWidget::setParent () function to change the ownership of a QDialog widget.

What is the default location of a qdialog?

Note that QDialog (and any other widget that has type Qt::Dialog) uses the parent widget slightly differently from other classes in Qt. A dialog is always a top-level widget, but if it has a parent, its default location is centered on top of the parent's top-level widget (if it is not top-level itself).


Video Answer


1 Answers

If you don't need manual resize, you can add

layout()->setSizeConstraint(QLayout::SetFixedSize);

to the dialog constructor, then the layout takes over the responsibility to automatically resize when widgets are shown or hidden.

like image 188
Zlatomir Avatar answered Oct 20 '22 04:10

Zlatomir