【问题标题】:QMainWindow independentQMainWindow 独立
【发布时间】:2013-08-22 07:38:52
【问题描述】:

我有两个 QMainWindows。我想当一个 QMessageBox 显示在一个带有 exec() 的 QMainWindow 上时,另一个 QMainWindow 不会被阻止。

两个QMainWindow必须是独立的。

这是怎么做到的?

【问题讨论】:

  • 这和QThread有什么关系?
  • 暂时没有。但我认为 QmainWindows 必须像 QThreads 一样独立。

标签: qt qmainwindow


【解决方案1】:

它与 QThread 无关,Qt 文档指出您在 QT 应用程序中只能有 ONE GUI 线程。

您应该做的是设置模态标志以使对话框模态,因此它将是与其父窗口相关的模态。在执行对话框之前,调用:

pDialog->setWindowModality( Qt::WindowModal );

别忘了为你的对话框对象设置一个合适的parent

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.

【讨论】:

    【解决方案2】:

    使用show() 方法来显示每个QMainWindow 而不是exec()

    【讨论】:

    • QMainWindows 与 show 一起显示。我需要对 QMessageBox 使用 exec 来处理结果。
    猜你喜欢
    • 2021-01-19
    • 1970-01-01
    • 2014-06-05
    • 1970-01-01
    • 2016-04-16
    • 1970-01-01
    • 1970-01-01
    • 2016-03-24
    • 2014-09-03
    相关资源
    最近更新 更多