PDA

View Full Version : Qt 4.7: problem with restoreGeometry / saveGeometry on Linux (Ubuntu)?



agarny
7th January 2011, 16:23
Hi,

I was wondering someone had ever come across the case where saveGeometry and restoreGeometry work fine on Windows and Mac OS X, but has a strange (?) behaviour on Linux (Ubuntu 10.10 at least). Basically, I have some code that saves the geometry of my application:


QSettings settings(SETTINGS_INSTITUTION, appName);

settings.setValue(SETTINGS_GENERAL_GEOMETRY, saveGeometry());

and, in the same way, I have some code to retrieve it:


QSettings settings(SETTINGS_INSTITUTION, appName);

restoreGeometry(settings.value(SETTINGS_GENERAL_GE OMETRY).toByteArray());

Now, as I said above, everything works fine and as expected on Windows and Mac OS X, but for some unknown reason (to me, at least!), the Y position of the main window gets shifted every time I start my application. In fact, it gets shifted down by 29 pixels until it reaches the bottom of my screen, at which point it stays there.

I traced the Y position of my main window (using pos().y()) and was surprised to find out that it returned 53 while it should have been 24 (because of the Ubuntu bar at the top). So, yes, 53-24 gives us our (infamous) 29 pixels. I tried to autohide the Ubuntu bar at the top, just to see whether it would make a difference, but to no avail.

So... has anyone ever across that problem? If so, is there something that can be done about it?

Cheers, Alan.

agarny
10th January 2011, 14:50
So, as anyone ever come across the above? Surely, I must not be the only one facing that problem, and who wants and needs a solution for it?...

wysota
10th January 2011, 14:59
My guess would be it is caused by a non-compliant implementation of the window manager (are you using Metacity or Compiz?) which doesn't include the window decoration in some geometry calculation or something like this. Try switching to a different window manager and see if the problem persists.

agarny
10th January 2011, 15:11
Very good point about the window manager! I am indeed using Compiz and having now disabled it, it all works fine. Argh, I hate implementations that are not compliant! :( In any case, thanks a lot for the hint, there is clearly nothing I can do about it (or is there?).

wysota
10th January 2011, 15:15
In any case, thanks a lot for the hint, there is clearly nothing I can do about it (or is there?).
Well... you can abandon compiz, that's for sure ;) You can also modify either Compiz or Qt to be compatible with each other, they are both open-source. Or you can ask someone to do it for you, of course.

agarny
10th January 2011, 15:22
Well, I think I am just going to make a note of it in my application's documentation and that's it. :)

fightling
9th May 2012, 10:53
Try to save/restore the window state with saveState() and restoreState() too. In combination this works on ubuntu to get the correct geometry.