【问题标题】:How to create a Window which is like messageBox in PyQt [duplicate]如何在 PyQt 中创建一个类似于 messageBox 的窗口 [重复]
【发布时间】:2019-06-20 07:58:14
【问题描述】:

PyQt 中的 MessageBox 不会访问父窗口...我尝试实现自定义 messageBox。但没有什么对我有用。

我尝试使用 QWidget,但使用 Qwidget,小部件被放置在 mainWindow 本身,如下图所示

然后我实现了对话框,它工作正常,但问题是当对话框打开时我们也可以访问主窗口。我希望它就像打开对话框时无法访问 mainWindow。

class MainClass(QtGui.QDialog):
  def __init__(self, parent=None):
    super(MainClass, self).__init__(parent)
    self.setParent(parent)

    #widgets added below
    ...

有人可以帮忙吗?

【问题讨论】:

  • 使用exec_()而不是show()打开它...

标签: python pyqt pyqt4 pyside


【解决方案1】:

我不知道我是否理解你的问题,但如果你的问题只是 如果您的对话框不会阻止对同一应用程序中其他可见窗口的输入,则解决方案是 setModal(True)。

你可以像胚胎说的那样用 exec_ 而不是 show,或者手动 setModal。

class MainClass(QtGui.QDialog):
    def __init__(self, parent=None):
        super(MainClass, self).__init__(parent)
        self.setParent(parent)
        self.setModal(True)
        #widgets added below

这里有一个类似的问题:How to create a modal window in pyqt?

【讨论】:

  • 是的,它对我有用...谢谢
猜你喜欢
  • 1970-01-01
  • 2018-02-11
  • 1970-01-01
  • 2014-09-02
  • 1970-01-01
  • 2014-11-11
  • 2014-04-05
  • 2021-01-28
  • 1970-01-01
相关资源
最近更新 更多