tags:

views:

998

answers:

2

Is there a way to specify a child's initial window position in Qt?

I have an application that runs on Linux and Windows and it looks like the default behavior of Qt lets the Window Manager determine the placement of the child windows.

On Windows, this is in the center of the screen the parent is on which seems reasonable.

On Linux, in GNOME (metacity) it is always in the upper left-hand corner which is annoying. I can't find any window manager preferences for metacity that allow me to control window placement so I would like to override that behavior.

+2  A: 

Qt Window Geometry

Call the move(x, y) method on the child window before show(). The default values for x and y are 0 so that's why it appears in the upper left-hand corner.
You can also use the position of the parent window to compute a relative position for the child.

kokos
A: 

Generally, I'd recommend not forcing window positions unless your application has some very special windowing requirements. It's the window manager's job to determine where new windows are put and most of them do a good job. If MetaCity isn't picking a good position, then that's its problem.

If you do your own window placement you may get a better result then what a poor window manager would give, but you'll also miss out on the intelligent window placement algorithms available in more advanced window managers.

Parker