From acaf6d177dd04e5fc6344c27088256cbf98bf74f Mon Sep 17 00:00:00 2001 From: Ye ShanShan Date: Mon, 22 Apr 2024 21:18:19 +0800 Subject: [PATCH] fix: text color of ToolTip doesn't change with theme palette.toolTipText doesn't change with theme. TODO: we should support to use ColorSelector for QQuickItem. Issue: https://github.com/linuxdeepin/developer-center/issues/8073 --- qt6/src/qml/FlowStyle.qml | 4 ++++ qt6/src/qml/ToolTip.qml | 7 +++++-- src/private/dquickcontrolpalette.cpp | 7 +++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/qt6/src/qml/FlowStyle.qml b/qt6/src/qml/FlowStyle.qml index 556c7780d..8e140461d 100644 --- a/qt6/src/qml/FlowStyle.qml +++ b/qt6/src/qml/FlowStyle.qml @@ -600,6 +600,10 @@ QtObject { property int verticalPadding: 4 property int horizontalPadding: 5 property int height: 24 + property D.Palette text: D.Palette { + normal: Qt.rgba(0, 0, 0, 1) + normalDark: Qt.rgba(1, 1, 1, 1) + } } property QtObject alertToolTip: QtObject { diff --git a/qt6/src/qml/ToolTip.qml b/qt6/src/qml/ToolTip.qml index 4421f091d..0823d54d4 100644 --- a/qt6/src/qml/ToolTip.qml +++ b/qt6/src/qml/ToolTip.qml @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: LGPL-3.0-or-later -import QtQuick 2.11 +import QtQuick import QtQuick.Templates as T import org.deepin.dtk 1.0 as D import org.deepin.dtk.style 1.0 as DS @@ -13,6 +13,8 @@ T.ToolTip { x: parent ? (parent.width - implicitWidth) / 2 : 0 y: -implicitHeight - 3 + property D.Palette textColor: DS.Style.toolTip.text + implicitWidth: DS.Style.control.implicitWidth(control) implicitHeight: DS.Style.control.implicitHeight(control) @@ -23,13 +25,14 @@ T.ToolTip { closePolicy: T.Popup.CloseOnEscape | T.Popup.CloseOnPressOutsideParent | T.Popup.CloseOnReleaseOutsideParent contentItem: Text { + property alias textColor: control.textColor horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignVCenter text: control.text font: control.font wrapMode: Text.WordWrap opacity: enabled ? 1.0 : 0.4 - color: control.palette.toolTipText + color: D.ColorSelector.textColor } background: FloatingPanel { diff --git a/src/private/dquickcontrolpalette.cpp b/src/private/dquickcontrolpalette.cpp index 627251629..8afa34260 100644 --- a/src/private/dquickcontrolpalette.cpp +++ b/src/private/dquickcontrolpalette.cpp @@ -28,7 +28,8 @@ DQUICK_BEGIN_NAMESPACE static inline bool _d_isControlItem(QQuickItem *item) { #define _D_FOR_EACH_SIMILAR_CONTROL_ITEM(F) \ F(QQuickControl), \ - F(QQuickTextField) + F(QQuickTextField), \ + F(QQuickText) #if defined(QT_NAMESPACE) #define SIMILAR_CONTROL_ITEM_NAMESPACE_STR1(NAME, Item) #NAME "::" #Item @@ -461,7 +462,9 @@ void DQuickControlColorSelector::setControl(QQuickItem *newControl) connect(palette, &QQuickPalette::changed, this, &DQuickControlColorSelector::updateControlTheme); #endif connect(m_control, SIGNAL(paletteChanged()), this, SLOT(updateControlTheme())); - connect(m_control, SIGNAL(hoveredChanged()), this, SLOT(updateControlState())); + if (m_control->metaObject()->indexOfSignal("hoveredChanged()") != -1) { + connect(m_control, SIGNAL(hoveredChanged()), this, SLOT(updateControlState())); + } if (m_control->metaObject()->indexOfSignal("pressedChanged()") != -1) { connect(m_control, SIGNAL(pressedChanged()), this, SLOT(updateControlState())); }