简体   繁体   中英

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.
    Leave all options as default, except the project name (I called mine "bob").
    Set the build target as 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:

     #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).

As per more popular request, a rationale of why I reckon the above howto detailed guide is a reproductible exemple of the problem

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.

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.

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).

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); )

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?

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).

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).

Please have a look at:

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

and

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

and

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.

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. The version used to compile Qt Creator and the kit you are using for your code are obviously two different things. 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

Since it's a Qt's bug, there's not much we can do here...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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