How to create a modal window in pyqt?(如何在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 has setModal() as found 此处.
QDialog has setModal() as found here.
如文档所述:
默认情况下,该属性为 False 并且 show() 弹出对话框如下无模式.将此属性设置为 true 相当于设置QWidget.windowModality 到 Qt.ApplicationModal.
By default, this property is
Falseandshow()pops up the dialog as modeless. Setting this property to true is equivalent to settingQWidget.windowModalitytoQt.ApplicationModal.
正如@sebastian 指出的,您可以使用 exec().但是最好使用 exec_() 因为 sebastian 提到的也是一个 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中创建模态窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在pyqt中创建模态窗口?
基础教程推荐
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
