26

How can I prevent a QDialog in PyQt from being resizeable or maximazable? I don't want the window's size changed.

PAYRE Quentin
  • 341
  • 1
  • 12
Antoni4040
  • 2,297
  • 11
  • 44
  • 56

3 Answers3

75

Use setFixedSize:

mydialog.setFixedSize(width, height)
Avaris
  • 35,883
  • 7
  • 81
  • 72
5

The above answers are just fine, besides, you could set maximum and mini widths and heights manually, like this:

myDialog = QDialog()
myDialog.setMaximumWidth(myDialog.width())
myDialog.setMaximumHeight(myDialog.height())

or in short, you could use maximumSize as:

myDialog.setMaximumSize()

Just as in the above code....

Amin Matola
  • 137
  • 2
  • 7
0

To set fixed sized window or dialog box (QWidget in general) you could use setFixedSize(QSize) or setFixedSize(int, int) functions.

In PyQt5, use :-

custom_dialog.setFixedSize(QSize(width, height)) # setFixedSize(QSize)

or

custom_dialog.setFixedSize(width, height) # setFixedSize(int, int)

You must import

from PyQt5.QtCore import  QSize

You could also use

custom_dialog.setFixedSize(custom_dialog.size())

Other Related Functions

setFixedWidth(int)

setFixedHeight(int)

anoopknr
  • 3,177
  • 2
  • 23
  • 33