[英]How to create a modal window in pyqt?
I looked into the documentation and i found 'self.setWindowModality(QtCore.Qt.WindowModal)'. 我查看了文档,发现'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. 我将此函数添加到我的' init '函数中,但是仍然无法创建模态对话框。
Any help will be appreciated, 任何帮助将不胜感激,
Thank You. 谢谢。
QDialog
has setModal()
as found here . QDialog
在这里找到了 setModal()
。
As the docs state: 正如文档所述:
By default, this property is
False
andshow()
pops up the dialog as modeless.默认情况下,此属性为
False
,show()
将对话框弹出为无模式。 Setting this property to true is equivalent to settingQWidget.windowModality
toQt.ApplicationModal
.将此属性设置为true等同于将
QWidget.windowModality
设置为Qt.ApplicationModal
。
As @sebastian noted you could use exec()
. 正如@sebastian所说,你可以使用
exec()
。 However it is better to use exec_()
as the one sebastian mentioned is also a python call. 但是最好使用
exec_()
因为提到的sebastian也是一个python调用。
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. 如果这没有帮助,请发布您的代码,我会看看。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.