如何在pyqt中创建模式窗口? [英] How to create a modal window in pyqt?
问题描述
我查看了文档,发现是'self.setWindowModality(QtCore.Qt.WindowModal)'.
我将此功能添加到了" init "功能中,但是仍然无法创建模式对话框.
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.
推荐答案
QDialog
具有setModal()
,已发现文档状态如下:
默认情况下,此属性为
False
,并且show()
弹出对话框,如下所示: 无模式的.将此属性设置为true等同于设置QWidget.windowModality
到Qt.ApplicationModal
.
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
.
正如@sebastian指出的,您可以使用exec()
.但是,最好使用exec_()
,因为提到的一个塞巴斯蒂安也是python调用.
As @sebastian noted you could use exec()
. However it is better to use exec_()
as the one sebastian mentioned is also a python call.
示例:
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.
这篇关于如何在pyqt中创建模式窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!