diff --git a/application/widgets/customcontrol/ddbase.cpp b/application/widgets/customcontrol/ddbase.cpp index 44aae59..6b825a0 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 b73267b..f9ee156 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