fix: 修复黑色背景下蓝牙列表名称颜色显示错误

蓝牙设备名称对应的DLabel增加主题变化后改变颜色

Log:
Influence: 改变主题,观察蓝牙列表设备名称的颜色是否改变
Bug: https://pms.uniontech.com/bug-view-167961.html
Change-Id: I7a22e77688aa8767eb6e3439d9885cd871945cde
This commit is contained in:
donghualin 2022-12-08 11:13:16 +08:00
parent 455402d640
commit 460705c401
2 changed files with 18 additions and 1 deletions

View File

@ -60,8 +60,9 @@ SettingLabel::SettingLabel(QString text, QWidget *parent)
p.setColor(QPalette::Background, Qt::transparent);
this->setPalette(p);
m_label->setForegroundRole(QPalette::BrightText);
onThemeTypeChanged(DGuiApplicationHelper::instance()->themeType());
updateEnabledStatus();
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &SettingLabel::onThemeTypeChanged);
}
void SettingLabel::addButton(QWidget *button, int space)
@ -80,6 +81,17 @@ void SettingLabel::updateEnabledStatus()
m_label->setPalette(p);
}
void SettingLabel::onThemeTypeChanged(DGuiApplicationHelper::ColorType themeType)
{
QPalette palette = m_label->palette();
if (themeType == DGuiApplicationHelper::ColorType::LightType)
palette.setColor(QPalette::BrightText, Qt::black);
else
palette.setColor(QPalette::BrightText, Qt::white);
m_label->setPalette(palette);
}
void SettingLabel::changeEvent(QEvent *event)
{
if (event->type() == QEvent::EnabledChange)

View File

@ -28,6 +28,7 @@
#include <QStandardItemModel>
#include <dtkwidget_global.h>
#include <DGuiApplicationHelper>
#include "org_deepin_dde_airplanemode1.h"
@ -47,6 +48,7 @@ class DListView;
DWIDGET_END_NAMESPACE
DWIDGET_USE_NAMESPACE
DGUI_USE_NAMESPACE
using DBusAirplaneMode = org::deepin::dde::AirplaneMode1;
@ -68,6 +70,9 @@ protected:
void updateEnabledStatus();
private Q_SLOTS:
void onThemeTypeChanged(DGuiApplicationHelper::ColorType themeType);
private:
DLabel *m_label;
QHBoxLayout *m_layout;