简体   繁体   English

可能的 Qt5 错误:调用 setFixedSize() 禁用主窗口的关闭按钮(在 Win7 下)

[英]Possible Qt5 bug: calling setFixedSize() disables the main window's close button (under Win7)

I'm posting this mainly because I wasted a bit of time groping for a solution, and also out of curiosity.我发布这个主要是因为我浪费了一点时间摸索解决方案,也是出于好奇。

As per popular request, a step by step reproducible example:根据流行的要求,一步一步可重现的例子:

  1. create a Qt widget project from Qt designer.从 Qt 设计器创建一个 Qt 小部件项目。
    Leave all options as default, except the project name (I called mine "bob").将所有选项保留为默认值,除了项目名称(我称我的为“bob”)。
    Set the build target as MinGW X64将构建目标设置为 MinGW X64

  2. compile and launch the executable with the default auto-generated code skeleton (I did it in debug mode but release doesn't work either).使用默认的自动生成的代码框架编译并启动可执行文件(我在调试模式下完成,但发布也不起作用)。
    Check that the main window is resizeable and the close button in the right top corner works as expected.检查主窗口是否可调整大小以及右上角的关闭按钮是否按预期工作。

  3. open the file "mainwindow.cpp" and add the setFixedSize invocation like so:打开文件“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; }
  4. Recompile, relaunch and check that the window is now refusing to resize (as it should), and the close button does not close the window anymore, but allows to drag it around just as if you had clicked the title bar instead (which it shouldn't).重新编译,重新启动并检查窗口现在是否拒绝调整大小(应该如此),并且关闭按钮不再关闭窗口,但允许将其拖动,就像您单击标题栏一样(它应该't)。

As per more popular request, a rationale of why I reckon the above howto detailed guide is a reproductible exemple of the problem根据更受欢迎的要求,为什么我认为上述 howto 详细指南是问题的可重现示例

Minimal:最小:

check查看

Minimal and readable:最小且可读:

check查看

Make sure all information necessary to reproduce the problem is included in the question itself:确保问题本身包含重现问题所需的所有信息:

check查看

Use individual code blocks for each file or snippet you include.为您包含的每个文件或片段使用单独的代码块。 Provide a description for the purpose of each block:为每个块的用途提供描述:

check, unless you want me to dump all the default files of a Qt widget project there.检查,除非您希望我在那里转储 Qt 小部件项目的所有默认文件。

Describe the problem:描述问题:

done, twice.完成,两次。

Use a brief but descriptive summary of your problem as the title of your question:使用简短但描述性的问题摘要作为问题的标题:

check查看

Eliminate any issues that aren't relevant to the problem:消除与问题无关的任何问题:

trying hard to, but apparently with limited success努力尝试,但显然收效甚微

Double-check that your example reproduces the problem:仔细检查您的示例是否重现了问题:

check, abundantly.检查,丰富。

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:关闭系统并重新启动它可能会有所帮助,或者将示例传输到新环境以确认它确实提供了问题的示例:

Well, sorry guys but I don't feel like reformatting my PC just to possibly fix a trite problem that is easily solved.好吧,对不起,伙计们,我不想重新格式化我的电脑只是为了解决一个很容易解决的陈腐问题。 I'm mostly publishing this out of curiosity, as well as a courtesy to fellow programmers who might encounter the same problem, I reckon I've done enough now.我主要是出于好奇而发布这篇文章,也是对可能遇到同样问题的程序员的礼貌,我想我现在已经做得足够了。

So now, for the description of the problem:所以现在,对于问题的描述:

Apparently, calling setFixedSize(geometry().size()) in the main window constructor of a standard Qt Widgets application (as advised on this venerable Qt forums thread ) has the strange side effect of invalidating the system close button on my Windows 7 system.显然,调用setFixedSize(geometry().size())在标准的Qt Widgets应用程序(如建议在主窗口中构造这所古老的Qt论坛线程)有我的Windows 7系统上无效的系统关闭按钮的奇怪的副作用.

As if the click events just fell through the button, clicking it will simply grab the window and allow to drag it around, but will not close it.就好像点击事件刚刚落下按钮一样,点击它只会抓住窗口并允许拖动它,但不会关闭它。
Except for that, everything works as expected (the window becomes unresizeable, the resize handle on the bottom right corner is inactive, you can still close the window by other standard means like Alt+F4, etc).除此之外,一切都按预期工作(窗口变得不可调整大小,右下角的调整大小手柄处于非活动状态,您仍然可以通过其他标准方式如 Alt+F4 等关闭窗口)。

A working (though platform-specific) method to make the main window fixed-size is to invoke使主窗口固定大小的工作(尽管特定于平台)方法是调用
setWindowFlags(windowFlags() | Qt::MSWindowsFixedSizeDialogHint);
before setting up the user interface ( ui->setupUi(this); )在设置用户界面之前( ui->setupUi(this);

Still I'm curious about this surprising behaviour.我仍然对这种令人惊讶的行为感到好奇。
Is there an obvious reason why changing a behaviour parameter of the layout manager should mess up a system button?为什么更改布局管理器的行为参数会弄乱系统按钮,是否有明显的原因?
Am I doing something wrong here?我在这里做错了吗?
Is that a reproducible bug, or the strange consequence of a local problem on my PC - wrong install or config maybe?这是一个可重现的错误,还是我 PC 上本地问题的奇怪后果 - 可能是安装或配置错误?

I'm using Qt Creator 4.11.0 based on Qt 5.14.0, with MinGW X64 as a target on a (French) Win7 OS (in test mode, for some reason, but I doubt the OS is to blame here).我正在使用基于 Qt 5.14.0 的 Qt Creator 4.11.0,将 MinGW X64 作为(法国)Win7 操作系统上的目标(处于测试模式,出于某种原因,但我怀疑这里应该归咎于操作系统)。

According to the official bug tracker https://bugreports.qt.io there is indeed a bug affecting some versions (probably a regression introduced with Qt 5.12.5).根据官方错误跟踪器https://bugreports.qt.io确实存在影响某些版本的错误(可能是 Qt 5.12.5 引入的回归)。

Please have a look at:请看一看:

https://bugreports.qt.io/browse/QTBUG-79922 https://bugreports.qt.io/browse/QTBUG-79922

and

https://bugreports.qt.io/browse/QTBUG-78262 https://bugreports.qt.io/browse/QTBUG-78262

and

https://bugreports.qt.io/browse/QTBUG-78656 https://bugreports.qt.io/browse/QTBUG-78656

However, they report the issue has been fixed with Qt 5.14 and backported to Qt 5.13.2.但是,他们报告说该问题已在 Qt 5.14 中得到修复,并已向后移植到 Qt 5.13.2。

You are using Qt Creator compiled wiht Qt 5.14 but it is unclear to me if you are also compiling your application against Qt 5.14 or another version.您正在使用通过 Qt 5.14 编译的 Qt Creator,但我不清楚您是否也在针对 Qt 5.14 或其他版本编译您的应用程序。 The version used to compile Qt Creator and the kit you are using for your code are obviously two different things.用于编译 Qt Creator 的版本和用于代码的工具包显然是两个不同的东西。 Hence, I would suggest to check if you are indeed compiling your application with a version that is supposed to have the fix and if yes, report the issue to bugreports.qt.io因此,我建议检查您是否确实使用应该具有修复的版本编译您的应用程序,如果是,请将问题报告给 bugreports.qt.io

Since it's a Qt's bug, there's not much we can do here...由于这是 Qt 的错误,因此我们在这里无能为力...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM