Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

qt: after moving window off-screen, how to move it back to default position, including default positioning behaviour?

Tags:

layout

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?

like image 908
lemzwerg Avatar asked Dec 10 '25 17:12

lemzwerg


1 Answers

One solution is to store Windows original position and use that. For extra safety (in case screen resolution changes), check that entire window still fits on screen and move and even resize if it does not.

A hacky alternative would be to create and open empty, possibly transparent dummy window of the same size and see where it gets positioned. Then move the original there and close the dummy one. Reading your question carefully, I think this would do what you are after.

I don't know of a Qt way to ask Window Manager to reposition the window, so if you really need that, specify the OS etc details.

like image 196
hyde Avatar answered Dec 13 '25 08:12

hyde



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!