Python 如何在pyqt中创建模态窗口?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24697347/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create a modal window in pyqt?
提问by user3135832
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.
我查看了文档,发现“self.setWindowModality(QtCore.Qt.WindowModal)”。
我将此函数添加到我的“ init”函数中,但仍然无法创建模态对话框。
Any help will be appreciated,
Thank You.
任何帮助将不胜感激,
谢谢。
采纳答案by Shadow9043
QDialog
has setModal()
as found here.
QDialog
已setModal()
找到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
.
默认情况下,这个属性是
False
和show()
弹出的对话框与非模态。将此属性设置为 true 等同于设置QWidget.windowModality
为Qt.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.
正如@sebastian 指出的那样,您可以使用exec()
. 但是最好使用,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.
如果这没有帮助,请发布您的代码,我会看看。