Qt World Summit: Register Today!

Qt 4.8.6 - Parent Window on Linux

  • On Windows if I create 2 windows, with one being the parent of the other the child window becomes a floating window. Namely the child cannot go underneath the parent window. On my Linux box this behavior doesn't seem to work. My code is:

    #include <QApplication>
    #include <QWidget>

    int main(int argc, char **argv)
    QApplication app(argc, argv);

    QWidget widget;
    QWidget widget2;
    widget2.setParent(&widget, widget.windowFlags());


    Any suggestions?

  • I guess it depends on a window manager.
    For example in Gnome3 a widget window from your example is always below widget2 window.
    But widget gets focus when mouse goes over it and I can put it above widget2 if I select "Always on Top" from a titlebar menu.

  • Ok, but is there a way to make windows on Linux behave in the same floating manor as on Windows?

    The closest I can see is to set the always on top flag for child windows, but that won't really work with children of children correctly.

  • Could always do something like this for the first window:

    Declare widget1 to have a member childWidget.virtual method for

    @ widget1.childWidget = &widget2;@

    And write out its virtual method for the focusInEvent() with something like:

    @void MainWindow::focusInEvent(QFocusEvent *)
    if (childWidget)

    Can propigate the raise for all other children as well.

Log in to reply