【问题标题】:QProgressDialog without close button [duplicate]没有关闭按钮的 QProgressDialog [重复]
【发布时间】:2013-06-04 14:26:33
【问题描述】:

是否可以删除QProgressDialog 的关闭按钮(见屏幕截图)?我在 docs/Google 中找不到任何有用的东西。

我使用模态QProgressDialog 来显示无限进程并阻止GUI,直到完成冗长的操作。因为应该阻止 GUI,所以我不希望用户能够关闭对话框。

【问题讨论】:

标签: c++ qt


【解决方案1】:

您可以通过清除适当的标志来隐藏每个窗口的关闭按钮:

Qt 5.0

QProgressDialog dlg;
dlg.setWindowFlags(dlg.windowFlags() & ~Qt::WindowCloseButtonHint);

Qt::WindowCloseButtonHint 0x08000000 添加关闭按钮。在某些平台上,这意味着 Qt::WindowSystemMenuHint 可以正常工作。

使用早期版本

    QProgressDialog dlg;
    dlg.setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);

在哪里

  • Qt::Window 代表窗口
  • Qt::WindowTitleHint 代表在窗口顶部显示标题
  • Qt::CustomizeWindowHint 代表不显示按钮

【讨论】:

  • 嗯,没用。可能是因为我使用QProgressDialog::exec() 显示对话框?
  • @sashoalm,在 Windows 中,按钮保持可见,但您无法按下它。您可能还应该隐藏帮助按钮以使其不可见。我也用exec 对其进行了测试。你的行为是怎样的?
  • 当我按原样粘贴您的代码时,关闭按钮保持不变并且未被禁用。当我删除帮助按钮和关闭按钮的标志时,帮助按钮消失,但关闭按钮仍然存在(并且是可点击的)。
  • @sashoalm,你使用 Linux 吗?可能是您的 Windows 管理器不支持此功能。您可以尝试玩标志。例如,dlg.setWindowFlags(Qt::WindowTitleHint | Qt::Window | Qt::CustomizeWindowHint); 生成一个完全没有按钮的窗口,Qt::Popup 生成一个没有边框的窗口。
  • 不,我使用的是 Windows 7。它可以在您的计算机上运行吗?这对我有用 - dlg.setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowTitleHint);,来自这个答案 - stackoverflow.com/a/15656707/492336
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-04-09
  • 1970-01-01
  • 2020-06-10
  • 1970-01-01
  • 2011-01-22
  • 1970-01-01
  • 2022-01-19
相关资源
最近更新 更多