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. How to bring all the application windows on top?
Forum Updated to NodeBB v4.3 + New Features

How to bring all the application windows on top?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 1 Posters 250 Views
  • 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.
  • M Offline
    M Offline
    Maksim Malofeev
    wrote on last edited by
    #1

    I have a lot of independent windows in my application (for which the transientParent value is null), so any window may be overridden by another application running in the system. Is there an easy way to bring all application windows to the front when I click on any one of them?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Maksim Malofeev
      wrote on last edited by
      #2

      I got the following solution

      connect(qGuiApp, &QGuiApplication::focusWindowChanged, this, [this](QWindow* focusWindow) {
            if (!focusWindow) {
              return;
            }
      
            auto windowList = QGuiApplication::allWindows();
            windowList.removeIf([focusWindow](QWindow* w) {
              return !w->isVisible() || w->transientParent() || w == focusWindow;
            });
      
            // Attempt to restore windows in the order in which they were opened.
            std::sort(windowList.begin(), windowList.end(), [](QWindow* l, QWindow* r) {
              return l->property(FOCUS_TIME_PROPERTY).value<qint64>() <
                     r->property(FOCUS_TIME_PROPERTY).value<qint64>();
            });
      
            for (auto window : windowList) {
              qDebug() << "Raise" << window->title();
              window->raise();
            }
      
            focusWindow->raise();
            focusWindow->setProperty(FOCUS_TIME_PROPERTY, QDateTime::currentMSecsSinceEpoch());
          });
      
      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