PDA

View Full Version : QMainWindow movable while maximized?



Byngl
5th June 2007, 20:05
Qt 4.2.2, Windows XP (Home)

The following code produces a maximized window that can be moved by the user:

QMainWindow xyzzy;
xyzzy.setWindowFlags(xyzzy.windowFlags() & ~(Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint));
xyzzy.showMaximized();
If I remove the Qt::WindowMaximizeButtonHint from the above code, I get a maximized window that cannot be moved. I do not know the size of the desktop, nor if the task bar is displayed. I need the main window to take up all desktop space and not to be able to be moved around.

wysota
5th June 2007, 20:17
How about using QWidget::showFullScreen() ?

Byngl
5th June 2007, 20:35
I still would like to have the title bar and the close button, and showFullScreen() gets rid of these.

Eldritch
5th June 2007, 20:42
I'm betting you're working in MSWindows.

Windows does this automatically. The underlying OS window style doesn't include a 'maximizeable' style, so certain behaviors are removed from the window. However, the underlying API doesn't prevent you from executing the 'maximize' operation. Since the window doesn't have a restore button on it (since it has no maximize button), I'm betting they decided that such a behavior was a Bad Thing -- so users can move the window.

You can work around this by injecting some Windows-specific code. (I've fixed exactly this bug in a commercial product... so I'm not sure if my employer will appreciate me giving the fix away. :P)

You'll need to modify how your window handles the WM_NCHITTEST (http://msdn2.microsoft.com/en-US/library/ms645618.aspx) message. To be complete, you should also try to customze the system menu for the window and the handing of WM_SYSCOMMAND events, since the user can still move the window via those options. There may be other holes, as well.

I haven't (yet) investigated if there are similar problems on X / Mac (my product also ships there, but only to a tiny fraction of our users compared to Windows).

Hope this helps.