Search code examples
c++qtuser-interfaceqtgui

Qt Child Window Placement


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.


Solution

  • Qt Widget 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.