Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Setting main Window on top using flags parameter not working as I expected
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 1.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    David A.
    wrote on last edited by
    #1

    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: {
                Qt.quit();
            }
        }
    }
    

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

    Comparison

    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;
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    
        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();
    }
    

    References:

    • Window QML Type
    • Windows Flags example
    • YARP qt viewer main.cpp
    p3c0P 1 Reply Last reply
    0
    • D David A.

      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: {
                  Qt.quit();
              }
          }
      }
      

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

      Comparison

      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;
          engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
      
          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();
      }
      

      References:

      • Window QML Type
      • Windows Flags example
      • YARP qt viewer main.cpp
      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @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 https://bugreports.qt.io

      157

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved