fix: Main interface does not gray out when losing focus#579
Merged
18202781743 merged 1 commit intolinuxdeepin:masterfrom Mar 3, 2026
Merged
fix: Main interface does not gray out when losing focus#57918202781743 merged 1 commit intolinuxdeepin:masterfrom
18202781743 merged 1 commit intolinuxdeepin:masterfrom
Conversation
18202781743
approved these changes
Mar 3, 2026
18202781743
requested changes
Mar 3, 2026
qt6/src/qml/DialogWindow.qml
Outdated
| @@ -1,4 +1,4 @@ | |||
| // SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. | |||
| // SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd. | |||
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
Contributor
deepin pr auto review这段代码是一个关于 Qt/QML 窗口管理的修改,主要增加了对 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
综合改进建议代码基于以上分析,建议对代码进行如下优化,主要是增加注释、优化逻辑顺序以及增强健壮性: // SPDX-FileCopyrightText: 2021 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick
import QtQuick.Window
import org.deepin.dtk 1.0 as D
import org.deepin.dtk.style 1.0 as DS
Window {
id: control
// ... (其他属性保持不变)
// 显式声明 transientParent 属性,用于动态管理父窗口关系
// 建议使用具体的 Window 类型(如果 QML 环境支持),或者保持 var 但添加文档说明
property var transientParentWindow: null
transientParent: transientParentWindow
Item {
id: content
// ... (内容保持不变)
}
/**
* 更新临时父窗口。
* 仅在模态为 WindowModal 且当前未设置父窗口时,
* 尝试将当前活动窗口设为父窗口,以保证正确的窗口层级。
*/
function updateTransientParent() {
// 非模态窗口或非应用模态窗口不需要强制设置 transientParent
if (control.modality !== Qt.WindowModal) {
return
}
// 如果尚未设置父窗口,或者父窗口设置错误(指向了自己),则尝试自动查找
if (!transientParentWindow || transientParentWindow === control) {
// 延迟获取 activeWindow,以确保触发显示该窗口的父窗口已经变为 active
// 注意:这里直接使用 callLater 包裹赋值逻辑,比在 onVisibleChanged 中分开调用更安全
Qt.callLater(function() {
var candidate = Qt.application.activeWindow
// 双重检查:确保 candidate 存在、不是当前窗口、且当前窗口仍然需要父窗口
if (candidate &&
candidate !== control &&
control.modality === Qt.WindowModal &&
!transientParentWindow) {
transientParentWindow = candidate
}
})
}
}
Component.onCompleted: {
updateTransientParent()
}
onVisibleChanged: {
if (!control.visible) {
return
}
// 尝试更新父窗口关系
updateTransientParent()
// 确保窗口显示在最上层并获得焦点
// 使用 callLater 避免与窗口显示事件冲突
Qt.callLater(function () {
control.raise()
control.requestActivate()
})
}
onClosing: function(close) {
// ... (保持不变)
}
}主要改进点总结:
|
18202781743
approved these changes
Mar 3, 2026
Contributor
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, JWWTSL The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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