How to bring all the application windows on top?
-
I have a lot of independent windows in my application (for which the
transientParentvalue 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? -
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()); });