From fe88103473803b2caad5ed1967ccb3cc9485ccc2 Mon Sep 17 00:00:00 2001 From: zhanghongyuan Date: Thu, 27 Aug 2026 14:43:43 +0800 Subject: [PATCH] feat(widget): add hover border effect to RoundColorWidget MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add enter/leave event handlers to draw a theme-aware hover border on the round color button (15% black in light, 15% white in dark). 为圆形颜色按钮添加鼠标悬停边框效果,浅色主题用15%黑、深色主题用15%白。 Log: 添加RoundColorWidget悬停边框效果 PMS: TASK-394181 Influence: 颜色选项按钮鼠标悬停时显示边框反馈,提升交互体验,不影响选中态显示。 --- reader/widgets/RoundColorWidget.cpp | 36 +++++++++++++++++++++++++---- reader/widgets/RoundColorWidget.h | 26 +++++++++++++++++++-- 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/reader/widgets/RoundColorWidget.cpp b/reader/widgets/RoundColorWidget.cpp index 9a28f5838..2c1086dc6 100644 --- a/reader/widgets/RoundColorWidget.cpp +++ b/reader/widgets/RoundColorWidget.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd. +// Copyright (C) 2019 - 2026 Uniontech Software Technology Co.,Ltd. // SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -47,9 +47,28 @@ void RoundColorWidget::mousePressEvent(QMouseEvent *event) } } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +void RoundColorWidget::enterEvent(QEvent *event) +#else +void RoundColorWidget::enterEvent(QEnterEvent *event) +#endif +{ + qCDebug(appLog) << "RoundColorWidget enterEvent"; + m_isHovered = true; + update(); + DWidget::enterEvent(event); +} + +void RoundColorWidget::leaveEvent(QEvent *event) +{ + qCDebug(appLog) << "RoundColorWidget leaveEvent"; + m_isHovered = false; + update(); + DWidget::leaveEvent(event); +} + void RoundColorWidget::paintEvent(QPaintEvent *event) { - // qCDebug(appLog) << "RoundColorWidget paintEvent"; Q_UNUSED(event) QPainter painter(this); painter.setPen(Qt::NoPen); @@ -59,8 +78,6 @@ void RoundColorWidget::paintEvent(QPaintEvent *event) QRect squareRect = rect(); if (m_isSelected) { - // qCDebug(appLog) << "RoundColorWidget paintEvent m_isSelected"; - //draw select circle QColor highlightColor = DGuiApplicationHelper::instance()->applicationPalette().highlight().color(); QPen pen; pen.setBrush(QBrush(highlightColor)); @@ -68,6 +85,16 @@ void RoundColorWidget::paintEvent(QPaintEvent *event) painter.setPen(pen); QRect r = squareRect.adjusted(3, 3, -3, -3); painter.drawEllipse(r); + } else if (m_isHovered) { + bool isDark = DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType; + QColor hoverColor = isDark ? Qt::white : Qt::black; + hoverColor.setAlpha(38); + QPen pen; + pen.setBrush(QBrush(hoverColor)); + pen.setWidth(borderWidth); + painter.setPen(pen); + QRect r = squareRect.adjusted(3, 3, -3, -3); + painter.drawEllipse(r); } QPainterPath path; @@ -84,5 +111,4 @@ void RoundColorWidget::paintEvent(QPaintEvent *event) painter.setBrush(Qt::NoBrush); painter.drawEllipse(r); } - // qCDebug(appLog) << "RoundColorWidget paintEvent end"; } diff --git a/reader/widgets/RoundColorWidget.h b/reader/widgets/RoundColorWidget.h index c667ccf75..71c1e415e 100644 --- a/reader/widgets/RoundColorWidget.h +++ b/reader/widgets/RoundColorWidget.h @@ -1,5 +1,5 @@ -// Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd. -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// Copyright (C) 2019 - 2026 Uniontech Software Technology Co.,Ltd. +// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -8,6 +8,9 @@ #include #include +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include +#endif DWIDGET_USE_NAMESPACE @@ -52,6 +55,24 @@ class RoundColorWidget : public DWidget */ void mousePressEvent(QMouseEvent *event); + /** + * @brief enterEvent + * 鼠标进入事件,触发 hover 灰色边框 + * @param event + */ +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + void enterEvent(QEvent *event) override; +#else + void enterEvent(QEnterEvent *event) override; +#endif + + /** + * @brief leaveEvent + * 鼠标离开事件,取消 hover 灰色边框 + * @param event + */ + void leaveEvent(QEvent *event) override; + /** * @brief paintEvent * 绘制事件 @@ -61,6 +82,7 @@ class RoundColorWidget : public DWidget private: bool m_isSelected = false; + bool m_isHovered = false; QColor m_color; bool m_allnotify = false; };