Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.12.2, 5.12.6, 5.13.1, 5.13.2
-
None
Description
The change signal for the active property is emitted whenever the window loses/gains focus, but the value of the active property is always true.
Here's a minimal example to reproduce the problem:
import QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick.Controls 2.4ApplicationWindow { id: root width: 300 height: 400 visible: true onActiveChanged: { console.log("[MainWindow::onActiveChanged]") console.log(" active:", active) } Window { id: subWindow width: 300 height: 400 visible: true onActiveChanged: { console.log("[SubWindow::onActiveChanged]") console.log(" active:", subWindow.active) } color: "red" } }
EDIT:
I just noticed the comment in qwindow.cpp
/*! Returns \c true if the window should appear active from a style perspective. This is the case for the window that has input focus as well as windows that are in the same parent / transient parent chain as the focus window. To get the window that currently has focus, use QGuiApplication::focusWindow(). */
So, by that explanation, it's actually working as intended since subWindow'_s transient parent is _root. I can't recall reading that anywhere in the official documentation. Maybe that can be added?
Also, getting a change signal even though the resulting value is the same seems a bit odd to me. The documentation for Window::requestActivate() says: "Requests the window to be activated, i.e. receive keyboard focus.". But in this example when switched from one window to another, the previous window will obviously lose keyboard focus. But when we check for Window::active it will return true. Maybe I'm missing something about Windows' window API. But it seems confusing to me.