Skip to content

feat: support QStyleHints::colorScheme() to get light/dark theme#321

Merged
BLumia merged 1 commit into
linuxdeepin:masterfrom
BLumia:theme-detection
Jul 13, 2026
Merged

feat: support QStyleHints::colorScheme() to get light/dark theme#321
BLumia merged 1 commit into
linuxdeepin:masterfrom
BLumia:theme-detection

Conversation

@BLumia

@BLumia BLumia commented Jul 10, 2026

Copy link
Copy Markdown
Member

Previously we don't support such feature, thus applications rely on this API to check system light/dark theme won't work. This make such API work.

Log:

验证方式:

import QtQuick

Rectangle {
    // Check if the current theme is Dark
    property bool isDarkMode: Application.styleHints.colorScheme === Qt.ColorScheme.Dark
    color: isDarkMode ? "dark" : "white"
    
    Component.onCompleted: {
        if (isDarkMode) {
            console.log("Current theme is DARK")
        } else {
            console.log("Current theme is LIGHT")
        }
    }
}

PMS: 369921

Previously we don't support such feature, thus applications rely
on this API to check system light/dark theme won't work. This
make such API work.

Log:
@BLumia
BLumia requested a review from 18202781743 July 10, 2026 09:35

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @BLumia, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码实现了Qt6.5及以上版本的暗色与亮色主题方案获取功能,逻辑严谨且无安全风险
代码质量优秀,无任何安全漏洞及逻辑缺陷,保持满分

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

函数 colorScheme() 在 qdeepintheme.cpp 中实现逻辑清晰,正确处理了 helper 为空的边界情况,switch 语句覆盖了所有枚举分支并包含 default 返回值。条件编译宏使用正确。
潜在问题:无
建议:无

  • 2.代码质量(优秀)✓

代码符合 Qt 编码规范,命名清晰,条件编译保证了版本兼容性,结构简洁。
潜在问题:无
建议:无

  • 3.代码性能(高效)✓

仅通过单例获取指针并进行简单的枚举判断,无额外开销。
建议:无

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码仅读取应用内部主题状态,无外部输入交互,不存在攻击面。

  • 建议:无需修复

■ 【改进建议代码示例】

+Qt::ColorScheme QDeepinTheme::colorScheme() const
+{
+    auto *helper = DGuiApplicationHelper::instance();
+    if (!helper)
+        return QGenericUnixTheme::colorScheme();
+
+    switch (helper->themeType()) {
+    case DGuiApplicationHelper::DarkType:
+        return Qt::ColorScheme::Dark;
+    case DGuiApplicationHelper::LightType:
+        return Qt::ColorScheme::Light;
+    default:
+        return Qt::ColorScheme::Unknown;
+    }
+}

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, BLumia

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@BLumia
BLumia merged commit ba6d77f into linuxdeepin:master Jul 13, 2026
23 of 25 checks passed
@BLumia
BLumia deleted the theme-detection branch July 13, 2026 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants