Skip to content

Commit 6fe5e85

Browse files
JWWTSL18202781743
authored andcommitted
fix: Main interface does not gray out when losing focus
log: In the DialogWindow, when set to WindowModal, the transientParent is automatically set to Qt.application.activeWindow. Upon display, raise() and requestActivate() are called to ensure the main window correctly enters a grayed-out state. pms: bug-336201
1 parent 7c24dbf commit 6fe5e85

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

qt6/src/qml/DialogWindow.qml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2021 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44

@@ -33,6 +33,9 @@ Window {
3333
property real leftPadding: DS.Style.dialogWindow.contentHMargin
3434
property real rightPadding: DS.Style.dialogWindow.contentHMargin
3535

36+
property var transientParentWindow: null
37+
transientParent: transientParentWindow
38+
3639
Item {
3740
id: content
3841
palette: control.active ? D.DTK.palette : D.DTK.inactivePalette
@@ -60,6 +63,30 @@ Window {
6063
}
6164
}
6265

66+
function updateTransientParent() {
67+
if (control.modality !== Qt.WindowModal)
68+
return
69+
if (!transientParentWindow || transientParentWindow === control) {
70+
var candidate = Qt.application.activeWindow
71+
if (candidate && candidate !== control)
72+
transientParentWindow = candidate
73+
}
74+
}
75+
76+
Component.onCompleted: {
77+
updateTransientParent()
78+
}
79+
80+
onVisibleChanged: {
81+
if (!control.visible)
82+
return
83+
updateTransientParent()
84+
Qt.callLater(function () {
85+
control.raise()
86+
control.requestActivate()
87+
})
88+
}
89+
6390
onClosing: function(close) {
6491
// close can't reset sub control's hovered state. pms Bug:168405
6592
// if we need to close, we can add closing handler to set `close.acceped = true`

0 commit comments

Comments
 (0)