qt获取窗口的右上角位置_qt:将窗口移出屏幕后,如何将其移回到默认位置,包括默认定位行为?...

[qt 4.8]

To get correct window dimensions including its frame, I do the following (as described e.g. here, see comment from Daniel Hedberg).

mainWindow.move(-50000, -50000);

mainWindow.show();

// do something with the window dimensions

mainWindow.move(0, 0);

mainWindow.show()

This works fine, however, I have a problem with the move(0,0) call: It makes the window always appear at position (0,0), while I would like to have the default behaviour, this is, the application only suggests to the window manager that (0,0) is a good place to position the window, and the WM might decide to shift it if necessary to avoid overlapping. In other words, I would like to switch back to Qt's default behaviour as if there weren't a call to move at all.

How can I do that?

解决方案

Looking into the source code of Qt, I can now partially answer my own question: To convert a call to move into a suggestion for positioning instead of a request, do this:

mainWindow.move(100, 100);

mainWindow.setAttribute(Qt::WA_Moved, false);

mainWindow.show();

I've tested the code under X11 using Qt 4.8.4, and hopefully it works with on other platforms too.

Unfortunately, this doesn't solve the very problem I have, namely to use show to get the (decorated) dimensions of an off-screen window which then gets moved to the screen, calling show again. It seems that the first call to show directly sets platform-specific window manager flags which aren't completely reset and reevaluated in the second call. Actually, I'm going to think that this is a bug in Qt, so I'll report it accordingly.

你可能感兴趣的:(qt获取窗口的右上角位置)