Skip to content

Commit ca2bac9

Browse files
itsXuStwangrong1069
authored andcommitted
fix: Remove hardcoded colors in disk health detection dialog for theme compatibility
- Remove hardcoded DPalette definitions (palette1-6) in DiskHealthDetectionDialog - Remove all setPalette() calls that prevented theme color following - Use option.palette.color(QPalette::Text) in DiskHealthDetectionDelegate for dynamic theme color - Preserve semantic colors for health status indicators (good/damaged/unknown) Log: Fix disk health panel font color not following dark mode theme Bug: https://pms.uniontech.com/bug-view-341105.html
1 parent 5c9967b commit ca2bac9

2 files changed

Lines changed: 1 addition & 25 deletions

File tree

application/widgets/diskhealthdetectiondelegate.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ void DiskHealthDetectionDelegate::paint(QPainter *painter, const QStyleOptionVie
134134
// qDebug() << "Drawing UNKNOWN status icon";
135135
painter->setPen(QColor("#777777"));
136136
} else {
137-
// qDebug() << "Drawing UNKNOWN status icon";
138-
painter->setPen(m_color);
137+
painter->setPen(option.palette.color(QPalette::Text));
139138
}
140139

141140
painter->drawText(paintRect.x() + 15, paintRect.y() + 20, text);

application/widgets/diskhealthdetectiondialog.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,27 +53,11 @@ void DiskHealthDetectionDialog::initUI()
5353
DLabel *diskLabel = new DLabel;
5454
diskLabel->setPixmap(iconDisk.pixmap(85, 85));
5555

56-
DPalette palette1;
57-
palette1.setColor(DPalette::Text, "#666666");
58-
59-
// 状态提示字体颜色
60-
DPalette palette4;
61-
palette4.setColor(DPalette::WindowText, QColor("#526A7F"));
62-
63-
// 表格内容颜色
64-
DPalette palette5;
65-
palette5.setColor(DPalette::Text, QColor("#001A2E"));
66-
67-
// 表头字体颜色
68-
DPalette palette6;
69-
palette6.setColor(DPalette::Text, QColor("#414D68"));
70-
7156
// 硬盘信息
7257
HardDiskInfo hardDiskInfo = DMDbusHandler::instance()->getHardDiskInfo(m_devicePath);
7358

7459
DLabel *serialNumberNameLabel = new DLabel(tr("Serial number")); // 序列号
7560
DFontSizeManager::instance()->bind(serialNumberNameLabel, DFontSizeManager::T8, QFont::Medium);
76-
serialNumberNameLabel->setPalette(palette1);
7761

7862
m_serialNumberValue = new DLabel;
7963
m_serialNumberValue->setText(hardDiskInfo.m_serialNumber);
@@ -82,7 +66,6 @@ void DiskHealthDetectionDialog::initUI()
8266

8367
DLabel *userCapacityNameLabel = new DLabel(tr("Storage")); // 用户容量
8468
DFontSizeManager::instance()->bind(userCapacityNameLabel, DFontSizeManager::T10, QFont::Medium);
85-
userCapacityNameLabel->setPalette(palette1);
8669

8770
m_userCapacityValue = new DLabel;
8871
m_userCapacityValue->setText(hardDiskInfo.m_size);
@@ -104,15 +87,13 @@ void DiskHealthDetectionDialog::initUI()
10487

10588
DLabel *healthStateLabel = new DLabel(tr("Health Status")); // 健康状态
10689
DFontSizeManager::instance()->bind(healthStateLabel, DFontSizeManager::T6, QFont::Medium);
107-
healthStateLabel->setPalette(palette1);
10890

10991
QIcon iconHealth = Common::getIcon("good");
11092
DLabel *iconHealthLabel = new DLabel;
11193
m_healthStateValue = new DLabel;
11294
DFontSizeManager::instance()->bind(m_healthStateValue, DFontSizeManager::T2, QFont::Medium);
11395
m_healthStateValue->setAccessibleName("healthState");
11496

115-
// 状态颜色
11697
DPalette paletteStateColor;
11798

11899
if (0 == healthStateValue.compare("PASSED", Qt::CaseInsensitive) || 0 == healthStateValue.compare("OK", Qt::CaseInsensitive)) {
@@ -154,7 +135,6 @@ void DiskHealthDetectionDialog::initUI()
154135
// 温度
155136
DLabel *temperatureLabel = new DLabel(tr("Temperature")); // 温度
156137
DFontSizeManager::instance()->bind(temperatureLabel, DFontSizeManager::T6, QFont::Medium);
157-
temperatureLabel->setPalette(palette1);
158138

159139
m_temperatureValue = new DLabel("-°C");
160140
DFontSizeManager::instance()->bind(m_temperatureValue, DFontSizeManager::T2, QFont::Medium);
@@ -192,14 +172,12 @@ void DiskHealthDetectionDialog::initUI()
192172
m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
193173
m_tableView->setSelectionMode(QAbstractItemView::NoSelection);
194174
m_tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
195-
m_tableView->setPalette(palette5);
196175

197176
m_diskHealthHeaderView = new DiskHealthHeaderView(Qt::Horizontal, this);
198177
m_tableView->setHorizontalHeader(m_diskHealthHeaderView);
199178

200179
DFontSizeManager::instance()->bind(m_tableView->horizontalHeader(), DFontSizeManager::T6, QFont::Medium);
201180
m_tableView->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignCenter);
202-
m_tableView->horizontalHeader()->setPalette(palette6);
203181

204182

205183
m_diskHealthDetectionDelegate = new DiskHealthDetectionDelegate(this);
@@ -332,7 +310,6 @@ void DiskHealthDetectionDialog::initUI()
332310
DLabel *stateTipsLabel = new DLabel;
333311
stateTipsLabel->setText(tr("Status: (G: Good | W: Warning | D: Damaged | U: Unknown)")); // 状态:(G: 良好 | W: 警告 | D: 损坏 | U: 未知)
334312
DFontSizeManager::instance()->bind(stateTipsLabel, DFontSizeManager::T8, QFont::Normal);
335-
stateTipsLabel->setPalette(palette4);
336313

337314
m_linkButton = new DCommandLinkButton(tr("Export", "button")); // 导出
338315
DFontSizeManager::instance()->bind(m_linkButton, DFontSizeManager::T8, QFont::Medium);

0 commit comments

Comments
 (0)