How can I block the increase of the window QDialog
and QWidget
?
For example, in the Skype login window you can not enlarge the window.
How can I block the increase of the window QDialog
and QWidget
?
For example, in the Skype login window you can not enlarge the window.
You can use the setFixedSize(const QSize &)
method of the QWidget
class to set a fixed size for a window. In practice it sets the maximum and minimum window size to the value that is passed by parameter.
If you want the size to be fixed but based on the components of the window, use setSizeConstraint(SizeConstraint)
of class QLayout
, with parameter SetFixedSize
:
layout()->setSizeConstraint(QLayout::SetFixedSize);
In the constructor you can do the following:
setFixedSize(size());
Or to use the recommended size instead of the default:
setFixedSize(sizeHint());
So the maximum and minimum size of the window will be set to the same value, it will not be resizable.
A better way to do this (which will resize the window if the content changes, but will make the window always be optimal for your content) is using QLayout::SetFixedSize
. See C. E. Gesser's Answer .
In addition, you can set the Qt::MSWindowsFixedSizeDialogHint
flag which in Windows creates a window with a thin border, visually indicating to the user that it is not resizable.
setWindowFlags(windowFlags() | Qt::MSWindowsFixedSizeDialogHint);
You can use the setFixedSize
method to do this.
Example:
setFixedSize(this->geometry().width(),this->geometry().height());