我有两个 QMainWindows。我想当 QMessageBox 显示在带有 exec() 的 QMainWindow 上时,另一个 QMainWindow 不会被阻止。
这两个 QMainWindow 必须是独立的。
这是怎么做的?
我有两个 QMainWindows。我想当 QMessageBox 显示在带有 exec() 的 QMainWindow 上时,另一个 QMainWindow 不会被阻止。
这两个 QMainWindow 必须是独立的。
这是怎么做的?
它与 QThread 无关,Qt 文档指出您在 QT 应用程序中只能有一个 GUI线程。
您应该做的是设置模态标志以使对话框模态,因此它将是与其父窗口相关的模态。在执行对话框之前,调用:
pDialog->setWindowModality( Qt::WindowModal );
并且不要忘记为您的对话框对象设置适当的父级。
Qt 文档指出: -
Modal Dialogs
A modal dialog is a dialog that blocks input to other visible windows in the
same application. Dialogs that are used to request a file name from the user or
that are used to set application preferences are usually modal. Dialogs can be
application modal (the default) or window modal.
使用show()
方法来显示每个QMainWindow
而不是exec()
.