From 0c8bee5141e05deb779eb51d357e0e25cf7fa522 Mon Sep 17 00:00:00 2001 From: renbin Date: Fri, 16 Aug 2024 18:18:47 +0800 Subject: [PATCH] fix: wrong volume button palette Use QPushButton insead of custom paint, set volume button background to transparent. Log: Fix wrong volume button palette. Bug: https://pms.uniontech.com/bug-view-234291.html --- src/widgets/toolbox_proxy.cpp | 32 +++++++++----------------------- src/widgets/toolbutton.cpp | 11 +++++------ src/widgets/toolbutton.h | 1 - 3 files changed, 14 insertions(+), 30 deletions(-) diff --git a/src/widgets/toolbox_proxy.cpp b/src/widgets/toolbox_proxy.cpp index 998bbc83..cf3ceb3f 100644 --- a/src/widgets/toolbox_proxy.cpp +++ b/src/widgets/toolbox_proxy.cpp @@ -1495,8 +1495,12 @@ void ToolboxProxy::slotThemeTypeChanged() // 取消阴影 pa.setColor(DPalette::Shadow, btnframecolor); DApplicationHelper::instance()->setPalette(m_pFullScreenBtn, pa); - DApplicationHelper::instance()->setPalette(m_pVolBtn, pa); DApplicationHelper::instance()->setPalette(m_pListBtn, pa); + + // 音量按钮取消边框背景 + pa.setColor(DPalette::Light, QColor(Qt::transparent)); + pa.setColor(DPalette::Dark, QColor(Qt::transparent)); + DApplicationHelper::instance()->setPalette(m_pVolBtn, pa); } else { textPalette.setColor(QPalette::WindowText, QColor(255, 255, 255, 40)); // 深色背景下时长显示置灰 textPalette.setColor(QPalette::Text, QColor(255, 255, 255, 40)); @@ -1516,8 +1520,11 @@ void ToolboxProxy::slotThemeTypeChanged() // 取消阴影 pa.setColor(DPalette::Shadow, framecolor); DApplicationHelper::instance()->setPalette(m_pFullScreenBtn, pa); - DApplicationHelper::instance()->setPalette(m_pVolBtn, pa); DApplicationHelper::instance()->setPalette(m_pListBtn, pa); + + pa.setColor(DPalette::Light, QColor(Qt::transparent)); + pa.setColor(DPalette::Dark, QColor(Qt::transparent)); + DApplicationHelper::instance()->setPalette(m_pVolBtn, pa); } if(m_pEngine->state() != PlayerEngine::CoreState::Idle) { @@ -2060,11 +2067,6 @@ void ToolboxProxy::updatePlayState() if (DGuiApplicationHelper::LightType == DGuiApplicationHelper::instance()->themeType()) { DPalette pa; - pa = m_pVolBtn->palette(); - pa.setColor(DPalette::Light, QColor(255, 255, 255, 255)); - pa.setColor(DPalette::Dark, QColor(255, 255, 255, 255)); - m_pVolBtn->setPalette(pa); - pa = m_pFullScreenBtn->palette(); pa.setColor(DPalette::Light, QColor(255, 255, 255, 255)); pa.setColor(DPalette::Dark, QColor(255, 255, 255, 255)); @@ -2083,11 +2085,6 @@ void ToolboxProxy::updatePlayState() } else { DPalette pa; - pa = m_pVolBtn->palette(); - pa.setColor(DPalette::Light, QColor(0, 0, 0, 255)); - pa.setColor(DPalette::Dark, QColor(0, 0, 0, 255)); - m_pVolBtn->setPalette(pa); - pa = m_pFullScreenBtn->palette(); pa.setColor(DPalette::Light, QColor(0, 0, 0, 255)); pa.setColor(DPalette::Dark, QColor(0, 0, 0, 255)); @@ -2114,12 +2111,6 @@ void ToolboxProxy::updatePlayState() if (DGuiApplicationHelper::LightType == DGuiApplicationHelper::instance()->themeType()) { DPalette pa; - - pa = m_pVolBtn->palette(); - pa.setColor(DPalette::Light, QColor(255, 255, 255, 255)); - pa.setColor(DPalette::Dark, QColor(255, 255, 255, 255)); - m_pVolBtn->setPalette(pa); - pa = m_pFullScreenBtn->palette(); pa.setColor(DPalette::Light, QColor(255, 255, 255, 255)); pa.setColor(DPalette::Dark, QColor(255, 255, 255, 255)); @@ -2138,11 +2129,6 @@ void ToolboxProxy::updatePlayState() } else { DPalette pa; - pa = m_pVolBtn->palette(); - pa.setColor(DPalette::Light, QColor(0, 0, 0, 255)); - pa.setColor(DPalette::Dark, QColor(0, 0, 0, 255)); - m_pVolBtn->setPalette(pa); - pa = m_pFullScreenBtn->palette(); pa.setColor(DPalette::Light, QColor(0, 0, 0, 255)); pa.setColor(DPalette::Dark, QColor(0, 0, 0, 255)); diff --git a/src/widgets/toolbutton.cpp b/src/widgets/toolbutton.cpp index f698e409..101b552b 100644 --- a/src/widgets/toolbutton.cpp +++ b/src/widgets/toolbutton.cpp @@ -11,6 +11,8 @@ namespace dmr { VolumeButton::VolumeButton(QWidget *parent) : QPushButton(parent), m_nVolume(100), m_bMute(false) { + setFlat(true); + setIconSize(QSize(36, 36)); setIcon(QIcon::fromTheme("dcc_volume")); installEventFilter(this); } @@ -46,6 +48,9 @@ void VolumeButton::setIcon(const QIcon &icon) { if (!icon.isNull()) { m_icon = icon; + + // 使用 PushButon 绘制图标 + QPushButton::setIcon(m_icon); } } @@ -77,12 +82,6 @@ void VolumeButton::leaveEvent(QEvent *ev) QPushButton::leaveEvent(ev); } -void VolumeButton::paintEvent(QPaintEvent *) -{ - QPainter painter(this); - painter.drawPixmap(rect(), m_icon.pixmap(rect().size())); -} - void VolumeButton::wheelEvent(QWheelEvent *we) { //qInfo() << we->angleDelta() << we->modifiers() << we->buttons(); diff --git a/src/widgets/toolbutton.h b/src/widgets/toolbutton.h index 3965e542..8c8df542 100644 --- a/src/widgets/toolbutton.h +++ b/src/widgets/toolbutton.h @@ -383,7 +383,6 @@ class VolumeButton: public QPushButton protected: void enterEvent(QEvent *ev) override; void leaveEvent(QEvent *ev) override; - void paintEvent(QPaintEvent *) override; void wheelEvent(QWheelEvent *wev) override; void focusOutEvent(QFocusEvent *ev) override; bool eventFilter(QObject *obj, QEvent *e) override;