Important: Please read the Qt Code of Conduct -

Setting main Window on top using flags parameter not working as I expected

  • Environment: Windows7 / Qt 5.4.2 with QtCreator 3.4.1 / MSVC2013

    I'm having problem setting a qml window on top. I create a new QtQuick 2.4 project and set the flags property as follows:

    import QtQuick 2.4
    import QtQuick.Window 2.2
    Window {
        visible: true
        flags: Qt.Window | Qt.WindowStaysOnTopHint
        MainForm {
            anchors.fill: parent
            mouseArea.onClicked: {

    The result is a window without title bar that stays on top.


    I have managed to do what I needed using C++ code, but it'd be great if I can learn why the previous QML code doesn't work...

    Just for completeness, you can do this in C++ (using Qt 5.4) as follows:

    int main(int argc, char *argv[])
        QGuiApplication app(argc, argv);
        QQmlApplicationEngine engine;
        QObject *topLevel = engine.rootObjects().value(0);
        QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
        Qt::WindowFlags flags = window->flags();
        window->setFlags(flags | Qt::WindowStaysOnTopHint);
        return app.exec();


  • Moderators

    @David-A. It works on Ubuntu with Qt 5.4.1. Result is a Window with title bar and stays on top as expected. Could be a bug on windows. Try searching on

Log in to reply