可能的 Qt5 错误:调用 setFixedSize() 会禁用主要 window 的关闭按钮(在 Win7 下)
Possible Qt5 bug: calling setFixedSize() disables the main window's close button (under Win7)
我发布这个主要是因为我浪费了一些时间来寻找解决方案,也是出于好奇。
根据普遍要求,一步一步可重现的例子:
从 Qt 设计器创建一个 Qt 小部件项目。
将所有选项保留为默认值,除了项目名称(我叫我的 "bob")。
将构建目标设置为 MinGW X64
使用默认 auto-generated 代码框架编译并启动可执行文件(我是在调试模式下完成的,但发布版也不起作用)。
检查主 window 是否可调整大小,右上角的关闭按钮是否按预期工作。
打开文件 "mainwindow.cpp" 并像这样添加 setFixedSize
调用:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
setFixedSize(geometry().size()); // <--- this line added
}
MainWindow::~MainWindow()
{
delete ui;
}
- 重新编译,重新启动并检查 window 现在拒绝调整大小(它应该如此),并且关闭按钮不再关闭 window,但允许拖动它就好像您点击了标题栏(它不应该)。
根据更受欢迎的要求,我认为上述 howto 详细指南的基本原理是问题的可重现示例
Minimal:
检查
Minimal and readable:
检查
Make sure all information necessary to reproduce the problem is
included in the question itself:
检查
Use individual code blocks for each file or snippet you include.
Provide a description for the purpose of each block:
检查,除非你想让我将 Qt 小部件项目的所有默认文件转储到那里。
Describe the problem:
完成,两次。
Use a brief but descriptive summary of your problem as the title of
your question:
检查
Eliminate any issues that aren't relevant to the problem:
努力尝试,但显然收效甚微
Double-check that your example reproduces the problem:
检查,大量。
It might help to shut the system down and restart it, or transport the
example to a fresh environment to confirm it really does provide an
example of the problem:
抱歉,伙计们,我不想重新格式化我的 PC 只是为了可能解决一个很容易解决的陈腐问题。我主要是出于好奇而发表这篇文章,同时也是对可能遇到同样问题的程序员的一种礼貌,我想我现在已经做得够多了。
那么现在,对于问题的描述:
显然,在标准 Qt Widgets 应用程序的主要 window 构造函数中调用 setFixedSize(geometry().size())
(如 this venerable Qt forums thread 所建议)具有使系统关闭按钮无效的奇怪副作用我的 Windows 7 系统。
好像点击事件刚好通过按钮,点击它只会抓住 window 并允许拖动它,但不会关闭它。
除此之外,一切都按预期工作(window 变得不可调整,右下角的调整大小手柄不活动,您仍然可以通过其他标准方式关闭 window,如 Alt+F4 等) .
使主要 window fixed-size 有效的(尽管 platform-specific)方法是调用
setWindowFlags(windowFlags() | Qt::MSWindowsFixedSizeDialogHint);
在设置用户界面之前 (ui->setupUi(this);
)
我仍然对这种令人惊讶的行为感到好奇。
更改布局管理器的行为参数会弄乱系统按钮是否有明显的原因?
我是不是做错了什么?
这是一个可重现的错误,还是我 PC 上本地问题的奇怪结果 - 可能是错误的安装或配置?
我正在使用基于 Qt 5.14.0 的 Qt Creator 4.11.0,在(法语)Win7 OS 上以 MinGW X64 为目标(出于某种原因,处于测试模式,但我怀疑OS 是罪魁祸首)。
根据官方错误跟踪器 https://bugreports.qt.io 确实存在影响某些版本的错误(可能是 Qt 5.12.5 引入的回归)。
请看:
https://bugreports.qt.io/browse/QTBUG-79922
和
https://bugreports.qt.io/browse/QTBUG-78262
和
https://bugreports.qt.io/browse/QTBUG-78656
但是,他们报告此问题已通过 Qt 5.14 修复并反向移植到 Qt 5.13.2。
您正在使用通过 Qt 5.14 编译的 Qt Creator,但我不清楚您是否也在针对 Qt 5.14 或其他版本编译您的应用程序。用于编译 Qt Creator 的版本和您用于代码的工具包显然是两个不同的东西。因此,我建议检查您是否确实使用应该具有修复的版本编译您的应用程序,如果是,请将问题报告给 bugreports.qt.io
由于这是 Qt 的错误,我们在这里无能为力...
我发布这个主要是因为我浪费了一些时间来寻找解决方案,也是出于好奇。
根据普遍要求,一步一步可重现的例子:
从 Qt 设计器创建一个 Qt 小部件项目。
将所有选项保留为默认值,除了项目名称(我叫我的 "bob")。
将构建目标设置为 MinGW X64使用默认 auto-generated 代码框架编译并启动可执行文件(我是在调试模式下完成的,但发布版也不起作用)。
检查主 window 是否可调整大小,右上角的关闭按钮是否按预期工作。打开文件 "mainwindow.cpp" 并像这样添加
setFixedSize
调用:#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); setFixedSize(geometry().size()); // <--- this line added } MainWindow::~MainWindow() { delete ui; }
- 重新编译,重新启动并检查 window 现在拒绝调整大小(它应该如此),并且关闭按钮不再关闭 window,但允许拖动它就好像您点击了标题栏(它不应该)。
根据更受欢迎的要求,我认为上述 howto 详细指南的基本原理是问题的可重现示例
Minimal:
检查
Minimal and readable:
检查
Make sure all information necessary to reproduce the problem is included in the question itself:
检查
Use individual code blocks for each file or snippet you include. Provide a description for the purpose of each block:
检查,除非你想让我将 Qt 小部件项目的所有默认文件转储到那里。
Describe the problem:
完成,两次。
Use a brief but descriptive summary of your problem as the title of your question:
检查
Eliminate any issues that aren't relevant to the problem:
努力尝试,但显然收效甚微
Double-check that your example reproduces the problem:
检查,大量。
It might help to shut the system down and restart it, or transport the example to a fresh environment to confirm it really does provide an example of the problem:
抱歉,伙计们,我不想重新格式化我的 PC 只是为了可能解决一个很容易解决的陈腐问题。我主要是出于好奇而发表这篇文章,同时也是对可能遇到同样问题的程序员的一种礼貌,我想我现在已经做得够多了。
那么现在,对于问题的描述:
显然,在标准 Qt Widgets 应用程序的主要 window 构造函数中调用 setFixedSize(geometry().size())
(如 this venerable Qt forums thread 所建议)具有使系统关闭按钮无效的奇怪副作用我的 Windows 7 系统。
好像点击事件刚好通过按钮,点击它只会抓住 window 并允许拖动它,但不会关闭它。
除此之外,一切都按预期工作(window 变得不可调整,右下角的调整大小手柄不活动,您仍然可以通过其他标准方式关闭 window,如 Alt+F4 等) .
使主要 window fixed-size 有效的(尽管 platform-specific)方法是调用
setWindowFlags(windowFlags() | Qt::MSWindowsFixedSizeDialogHint);
在设置用户界面之前 (ui->setupUi(this);
)
我仍然对这种令人惊讶的行为感到好奇。
更改布局管理器的行为参数会弄乱系统按钮是否有明显的原因?
我是不是做错了什么?
这是一个可重现的错误,还是我 PC 上本地问题的奇怪结果 - 可能是错误的安装或配置?
我正在使用基于 Qt 5.14.0 的 Qt Creator 4.11.0,在(法语)Win7 OS 上以 MinGW X64 为目标(出于某种原因,处于测试模式,但我怀疑OS 是罪魁祸首)。
根据官方错误跟踪器 https://bugreports.qt.io 确实存在影响某些版本的错误(可能是 Qt 5.12.5 引入的回归)。
请看:
https://bugreports.qt.io/browse/QTBUG-79922
和
https://bugreports.qt.io/browse/QTBUG-78262
和
https://bugreports.qt.io/browse/QTBUG-78656
但是,他们报告此问题已通过 Qt 5.14 修复并反向移植到 Qt 5.13.2。
您正在使用通过 Qt 5.14 编译的 Qt Creator,但我不清楚您是否也在针对 Qt 5.14 或其他版本编译您的应用程序。用于编译 Qt Creator 的版本和您用于代码的工具包显然是两个不同的东西。因此,我建议检查您是否确实使用应该具有修复的版本编译您的应用程序,如果是,请将问题报告给 bugreports.qt.io
由于这是 Qt 的错误,我们在这里无能为力...