From 469fc2c22ba0c3668e59b8560d08b67eb8fee4c4 Mon Sep 17 00:00:00 2001 From: xujin Date: Thu, 17 Sep 2026 15:09:00 +0800 Subject: [PATCH] fix: correct license dialog button disabled style MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Change the default background opacity for the custom push button from 0.15 to 0.05 when the button is disabled, so the disabled state renders as a lighter, flatter surface 2. Extract the QStyle::State_Enabled check into a named `enabled` const and only apply the 0.15/0.25/0.35 opacities for enabled, sunken and hover states respectively 3. Apply palette colors to QPalette::All color groups (Button and ButtonText) instead of only the Active group, otherwise the Disabled color group was ignored and the wrong color was painted 4. When the button is highlighted (i.e. the license agreement checkbox is unchecked and the button is disabled), use QPalette::Disabled/ WindowText for the text instead of the highlight color; once the checkbox is checked and the button becomes enabled, the text switches to the Active/Highlight color, making the two states clearly distinguishable Log: Adjusted the license dialog button styling so the disabled and enabled states are visually distinguishable Influence: 1. Open the license dialog with the agreement checkbox unchecked and verify the confirm button uses the disabled text color and the lighter 0.05 background 2. Check the agreement checkbox and verify the button text switches to the active highlight color and the background becomes 0.15 opacity 3. Verify hover and pressed states of the enabled button use 0.25 and 0.35 opacity respectively 4. Verify the button renders correctly under light, dark and high- contrast themes 5. Verify disabled buttons remain non-clickable and enabled buttons trigger the expected action 6. Verify the button also renders correctly when the style is applied outside of the dialog context (e.g. other windows using the same button class) fix: 修正许可协议对话框按钮禁用态样式 1. 将自定义按钮的默认背景透明度从 0.15 改为 0.05,使按钮在禁用状态下呈现 更浅、更平的视觉效果 2. 将 QStyle::State_Enabled 判断提取为具名常量 enabled,仅在启用状态下分 别应用 0.15、0.25、0.35 的透明度对应普通、按下和悬停状态 3. 将调色板颜色应用到 QPalette::All 所有颜色组(Button 与 ButtonText), 而不是仅应用到 Active 组,否则 Disabled 颜色组会被忽略,导致绘制颜色不 正确 4. 当按钮处于高亮状态时(即未勾选许可协议、按钮不可用),文字使用 QPalette::Disabled/WindowText 而非高亮色;勾选协议后按钮变为可用,文字才 切换到 Active/Highlight 高亮色,使两种状态清晰可区分 Log: 调整许可协议对话框按钮样式,使禁用态与可用态可明显区分 Influence: 1. 打开许可协议对话框,保持协议复选框未勾选,验证确认按钮使用禁用态文字 色以及更浅的 0.05 背景 2. 勾选协议复选框,验证按钮文字切换为活动高亮色、背景透明度变为 0.15 3. 验证可用按钮的悬停态与按下态分别使用 0.25 与 0.35 的透明度 4. 验证按钮在浅色、深色及高对比度主题下的渲染效果 5. 验证禁用按钮仍不可点击,可用按钮能触发预期操作 6. 验证在对话框之外的场景(例如使用同一按钮类的其他窗口)中按钮渲染同样 正确 PMS: BUG-360973 --- dde-license-dialog/src/content.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/dde-license-dialog/src/content.cpp b/dde-license-dialog/src/content.cpp index 634d60aa..a618873f 100644 --- a/dde-license-dialog/src/content.cpp +++ b/dde-license-dialog/src/content.cpp @@ -50,8 +50,11 @@ class LicenseDialogButton : public DPushButton { DPushButton::initStyleOption(option); - qreal backgroundOpacity = 0.15; - if (option->state.testFlag(QStyle::State_Enabled)) { + const bool enabled = option->state.testFlag(QStyle::State_Enabled); + + qreal backgroundOpacity = 0.05; + if (enabled) { + backgroundOpacity = 0.15; if (option->state.testFlag(QStyle::State_Sunken)) { backgroundOpacity = 0.25; } else if (option->state.testFlag(QStyle::State_MouseOver)) { @@ -61,11 +64,15 @@ class LicenseDialogButton : public DPushButton QColor backgroundColor(Qt::black); backgroundColor.setAlphaF(backgroundOpacity); - option->palette.setColor(QPalette::Button, backgroundColor); + option->palette.setColor(QPalette::All, QPalette::Button, backgroundColor); if (m_highlighted) { - QColor textColor = option->palette.highlight().color(); - option->palette.setColor(QPalette::ButtonText, textColor); + // 未勾选协议时按钮不可用,文字使用不可用态的常规文字色; + // 勾选后按钮可用,文字才使用活动色(高亮色),使两种状态可以区分。 + const QColor textColor = enabled + ? option->palette.color(QPalette::Active, QPalette::Highlight) + : option->palette.color(QPalette::Disabled, QPalette::WindowText); + option->palette.setColor(QPalette::All, QPalette::ButtonText, textColor); } option->state.setFlag(QStyle::State_MouseOver, false);