How to create a modal window in pyqt?
28,558
QDialog
has setModal()
as found here.
As the docs state:
By default, this property is
False
andshow()
pops up the dialog as modeless. Setting this property to true is equivalent to settingQWidget.windowModality
toQt.ApplicationModal
.
As @sebastian noted you could use exec()
. However it is better to use exec_()
as the one sebastian mentioned is also a python call.
Example:
my_dialog = QDialog(self)
my_dialog.exec_() # blocks all other windows until this window is closed.
If this doesn't help please post your code and I will have a look.
Author by
user3135832
Updated on July 13, 2020Comments
-
user3135832 almost 4 years
I looked into the documentation and i found 'self.setWindowModality(QtCore.Qt.WindowModal)'.
I added this function to my 'init' function, but however still was not able to create a modal dialog box.Any help will be appreciated,
Thank You. -
user3135832 almost 10 yearsSorry for wasting your time. I realised that what i was looking for was a system modal dialog, i should have read the docs properly. I'll edit the question. I apologise, but do you know if it is possible to create a system modal dialog in ppyqt for linux. Thanks.
-
Shadow9043 almost 10 yearsBy System Modal you mean that your window should be on top of every other applications window? This is generally a bad idea and will end up frustrating your end user(s).
-
user3135832 almost 10 yearsIts actually a license agreement for a linux distro.
-
sebastian almost 10 yearsFWIW: I of course meant to use
exec_
, I just happen to use the Qt reference usually. Sinceexec
not only a python call but a keyword - theexec
method can't exist in python anyway. -
bactone almost 3 yearshow to show a dialog blocks only some windows rather than the entire application?