From cf2627386a551707f2ef0dd672d991dd39fcbc51 Mon Sep 17 00:00:00 2001 From: xust Date: Mon, 24 Nov 2025 13:11:08 +0800 Subject: [PATCH] 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 --- .../widgets/diskhealthdetectiondelegate.cpp | 2 +- .../widgets/diskhealthdetectiondialog.cpp | 34 ------------------- 2 files changed, 1 insertion(+), 35 deletions(-) diff --git a/application/widgets/diskhealthdetectiondelegate.cpp b/application/widgets/diskhealthdetectiondelegate.cpp index 3acdb47..59c32c8 100644 --- a/application/widgets/diskhealthdetectiondelegate.cpp +++ b/application/widgets/diskhealthdetectiondelegate.cpp @@ -117,7 +117,7 @@ void DiskHealthDetectionDelegate::paint(QPainter *painter, const QStyleOptionVie } else if (text == "U") { painter->setPen(QColor("#777777")); } else { - painter->setPen(m_color); + painter->setPen(option.palette.color(QPalette::Text)); } painter->drawText(paintRect.x() + 15, paintRect.y() + 20, text); diff --git a/application/widgets/diskhealthdetectiondialog.cpp b/application/widgets/diskhealthdetectiondialog.cpp index 965dab5..a49e820 100644 --- a/application/widgets/diskhealthdetectiondialog.cpp +++ b/application/widgets/diskhealthdetectiondialog.cpp @@ -49,45 +49,23 @@ void DiskHealthDetectionDialog::initUI() DLabel *diskLabel = new DLabel; diskLabel->setPixmap(iconDisk.pixmap(85, 85)); - DPalette palette1; - palette1.setColor(DPalette::Text, "#666666"); - - DPalette palette2; - palette2.setColor(DPalette::Text, "#000000"); - - // 状态提示字体颜色 - DPalette palette4; - palette4.setColor(DPalette::WindowText, QColor("#526A7F")); - - // 表格内容颜色 - DPalette palette5; - palette5.setColor(DPalette::Text, QColor("#001A2E")); - - // 表头字体颜色 - DPalette palette6; - palette6.setColor(DPalette::Text, QColor("#414D68")); - // 硬盘信息 HardDiskInfo hardDiskInfo = DMDbusHandler::instance()->getHardDiskInfo(m_devicePath); DLabel *serialNumberNameLabel = new DLabel(tr("Serial number")); // 序列号 DFontSizeManager::instance()->bind(serialNumberNameLabel, DFontSizeManager::T8, QFont::Medium); - serialNumberNameLabel->setPalette(palette1); m_serialNumberValue = new DLabel; m_serialNumberValue->setText(hardDiskInfo.m_serialNumber); DFontSizeManager::instance()->bind(m_serialNumberValue, DFontSizeManager::T6, QFont::Medium); - m_serialNumberValue->setPalette(palette2); m_serialNumberValue->setAccessibleName("Serial number"); DLabel *userCapacityNameLabel = new DLabel(tr("Storage")); // 用户容量 DFontSizeManager::instance()->bind(userCapacityNameLabel, DFontSizeManager::T10, QFont::Medium); - userCapacityNameLabel->setPalette(palette1); m_userCapacityValue = new DLabel; m_userCapacityValue->setText(hardDiskInfo.m_size); DFontSizeManager::instance()->bind(m_userCapacityValue, DFontSizeManager::T10, QFont::Normal); - m_userCapacityValue->setPalette(palette2); m_userCapacityValue->setAccessibleName("Storage"); QVBoxLayout *diskInfoLayout = new QVBoxLayout; @@ -104,7 +82,6 @@ void DiskHealthDetectionDialog::initUI() DLabel *healthStateLabel = new DLabel(tr("Health Status")); // 健康状态 DFontSizeManager::instance()->bind(healthStateLabel, DFontSizeManager::T6, QFont::Medium); - healthStateLabel->setPalette(palette2); QIcon iconHealth = Common::getIcon("good"); DLabel *iconHealthLabel = new DLabel; @@ -112,7 +89,6 @@ void DiskHealthDetectionDialog::initUI() DFontSizeManager::instance()->bind(m_healthStateValue, DFontSizeManager::T2, QFont::Medium); m_healthStateValue->setAccessibleName("healthState"); - // 状态颜色 DPalette paletteStateColor; if (0 == healthStateValue.compare("PASSED", Qt::CaseInsensitive) || 0 == healthStateValue.compare("OK", Qt::CaseInsensitive)) { @@ -151,11 +127,9 @@ void DiskHealthDetectionDialog::initUI() // 温度 DLabel *temperatureLabel = new DLabel(tr("Temperature")); // 温度 DFontSizeManager::instance()->bind(temperatureLabel, DFontSizeManager::T6, QFont::Medium); - temperatureLabel->setPalette(palette2); m_temperatureValue = new DLabel("-°C"); DFontSizeManager::instance()->bind(m_temperatureValue, DFontSizeManager::T2, QFont::Medium); - m_temperatureValue->setPalette(palette2); m_temperatureValue->setAccessibleName("temperature"); QVBoxLayout *temperatureLayout = new QVBoxLayout; @@ -190,23 +164,16 @@ void DiskHealthDetectionDialog::initUI() m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows); m_tableView->setSelectionMode(QAbstractItemView::NoSelection); m_tableView->setEditTriggers(QAbstractItemView::NoEditTriggers); - m_tableView->setPalette(palette5); m_diskHealthHeaderView = new DiskHealthHeaderView(Qt::Horizontal, this); m_tableView->setHorizontalHeader(m_diskHealthHeaderView); DFontSizeManager::instance()->bind(m_tableView->horizontalHeader(), DFontSizeManager::T6, QFont::Medium); m_tableView->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignCenter); - m_tableView->horizontalHeader()->setPalette(palette6); m_diskHealthDetectionDelegate = new DiskHealthDetectionDelegate(this); m_tableView->setItemDelegate(m_diskHealthDetectionDelegate); - if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType) { - m_diskHealthDetectionDelegate->setTextColor(QColor("#C0C6D4")); - } else if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) { - m_diskHealthDetectionDelegate->setTextColor(QColor("#001A2E")); - } m_standardItemModel->setColumnCount(7); m_standardItemModel->setHeaderData(0, Qt::Horizontal, QString(" %1").arg(tr("ID"))); // 第一个需要向右对齐内容,15px @@ -314,7 +281,6 @@ void DiskHealthDetectionDialog::initUI() DLabel *stateTipsLabel = new DLabel; stateTipsLabel->setText(tr("Status: (G: Good | W: Warning | D: Damaged | U: Unknown)")); // 状态:(G: 良好 | W: 警告 | D: 损坏 | U: 未知) DFontSizeManager::instance()->bind(stateTipsLabel, DFontSizeManager::T8, QFont::Normal); - stateTipsLabel->setPalette(palette4); m_linkButton = new DCommandLinkButton(tr("Export", "button")); // 导出 DFontSizeManager::instance()->bind(m_linkButton, DFontSizeManager::T8, QFont::Medium);