From 3e6b707b1338c3aafa0ce2fd502e63f93fdfda3b Mon Sep 17 00:00:00 2001 From: wangrong Date: Fri, 6 Nov 2026 19:19:52 +0800 Subject: [PATCH] fix: center dialog on parent screen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Root cause: DTK6 DAbstractDialog::getParentGeometry() uses parentWidget()->window()->geometry() which returns position (0,0) on Wayland, causing dialogs to center on primary screen 2. Fix: override showEvent in DDBase to use parentWidget()->screen()->geometry() for centering, which returns correct screen geometry on both X11 and Wayland 3. Impact: all DDBase-derived dialogs now center on the screen where the parent window resides Log: fix dialog appearing on primary screen in multi-monitor setup Influence: 1. Test dialog positioning in dual-monitor Wayland session 2. Test dialog positioning in single-monitor session for regression 3. Verify all DDBase-derived dialogs appear on correct screen fix: 修复双屏环境下弹窗显示在主屏的问题 1. 根因:DTK6 DAbstractDialog::getParentGeometry() 使用 parentWidget()->window()->geometry(),在 Wayland 下返回 (0,0), 导致弹窗居中到主屏而非父窗口所在屏幕 2. 方案:在 DDBase 中覆盖 showEvent,使用 parentWidget()->screen()->geometry() 计算居中位置, 该接口在 X11 和 Wayland 下均返回屏幕物理几何 3. 影响:所有继承 DDBase 的弹窗将在父窗口所在屏幕居中显示 Log: 修复双屏环境下磁盘管理器弹窗显示在主屏的问题 Influence: 1. 测试双屏 Wayland 环境下弹窗定位 2. 测试单屏环境下弹窗定位(无回归) 3. 验证所有 DDBase 派生弹窗显示在正确屏幕 PMS: BUG-333047 --- application/widgets/customcontrol/ddbase.cpp | 13 +++++++++++++ application/widgets/customcontrol/ddbase.h | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/application/widgets/customcontrol/ddbase.cpp b/application/widgets/customcontrol/ddbase.cpp index 44aae59a..6b825a0d 100644 --- a/application/widgets/customcontrol/ddbase.cpp +++ b/application/widgets/customcontrol/ddbase.cpp @@ -7,6 +7,7 @@ #include "common.h" #include +#include DDBase::DDBase(QWidget *parent) : DDialog(parent) @@ -34,3 +35,15 @@ void DDBase::keyPressEvent(QKeyEvent *event) DDialog::keyPressEvent(event); } } + +void DDBase::showEvent(QShowEvent *event) +{ + if (parentWidget() && parentWidget()->screen()) { + QRect screenGeom = parentWidget()->screen()->geometry(); + QRect dialogGeom = geometry(); + int x = screenGeom.x() + (screenGeom.width() - dialogGeom.width()) / 2; + int y = screenGeom.y() + (screenGeom.height() - dialogGeom.height()) / 2; + move(x, y); + } + DDialog::showEvent(event); +} diff --git a/application/widgets/customcontrol/ddbase.h b/application/widgets/customcontrol/ddbase.h index b73267bf..f9ee156e 100644 --- a/application/widgets/customcontrol/ddbase.h +++ b/application/widgets/customcontrol/ddbase.h @@ -34,6 +34,12 @@ class DDBase : public DDialog * @param event事件 */ void keyPressEvent(QKeyEvent *event) override; + + /** + * @brief 显示事件,覆盖 DTK6 默认居中逻辑 + * @param event 显示事件 + */ + void showEvent(QShowEvent *event) override; }; #endif // DDBASE_H