[Qt-interest] Saving/restoring window position does not work in KDE 4 (but works in KDE 3.5.x)

Marcelo Magno T. Sales mmtsales at gmail.com
Mon Jan 5 00:03:22 CET 2009


Hi,

In an application, I save the main window size and position when the 
user exits and restore these properties again the next time the 
application is run. In KDE 3.5.9, the application works as expected 
(compiled with Qt 4.4.1). However, in KDE 4.1.3, every time the same 
application (compiled with Qt 4.4.3) is run, its window is placed a 
little lower than it was when the user last exited. I'm under the 
impression that the displacement is equivalent to the window decoration.

The following code runs when the user exits (called from the main window 
destructor):
---------------------------------
QSettings settings;
(...)
settings.setValue("Maximized",isMaximized());
if (!isMaximized()) {
    settings.setValue("WindowSize",size());
    settings.setValue("WindowPosition",pos());
}
(...)
---------------------------------

And the following runs when the application is started (called from the 
main window constructor):
---------------------------------
QSettings settings;
const int defaultX=(qApp->desktop()->width()-640)/2;
const int defaultY=(qApp->desktop()->height()-480)/2;
if (!settings.value("Maximized",false).toBool()) {
    resize(settings.value("WindowSize",QSize(640,480)).toSize());
    move(settings.value("WindowPosition",QPoint(defaultX,defaultY)).toPoint());
}
    else setWindowState(Qt::WindowMaximized);
---------------------------------

Is this code faulty or is this some unexpected behavior in KDE 4 or in 
Qt 4.4.3?

Thanks,

Marcelo



More information about the Qt-interest-old mailing list