From adaeb641d56c635f5ea4d006a118c75e4ea275eb Mon Sep 17 00:00:00 2001 From: wangyan Date: Tue, 10 Jan 2023 15:19:03 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20=E8=A7=A3=E5=86=B3qml=E5=9B=BE=E6=A0=87?= =?UTF-8?q?=E6=94=B9=E5=8F=98=E6=97=B6=E4=B8=8D=E5=AE=9E=E6=97=B6=E8=B7=9F?= =?UTF-8?q?=E9=9A=8F=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ukui-qml-style-helper/KyIcon.cpp | 11 ++++++++--- ukui-qml-style-helper/KyIcon.h | 6 ++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ukui-qml-style-helper/KyIcon.cpp b/ukui-qml-style-helper/KyIcon.cpp index c55ef2c..490b838 100644 --- a/ukui-qml-style-helper/KyIcon.cpp +++ b/ukui-qml-style-helper/KyIcon.cpp @@ -31,9 +31,11 @@ KyIcon::KyIcon(QQuickPaintedItem *parent) emit sunkenChanged(); emit onChanged(); emit icontypeChanged(); + emit iconNameChanged(); update(); }); } + connect(this, &KyIcon::iconNameChanged, this, &KyIcon::updateItem); connect(this, &KyIcon::hoverChanged, this, &KyIcon::updateItem); connect(this, &KyIcon::selectedChanged, this, &KyIcon::updateItem); connect(this, &KyIcon::hasFocusChanged, this, &KyIcon::updateItem); @@ -42,6 +44,7 @@ KyIcon::KyIcon(QQuickPaintedItem *parent) connect(this, &KyIcon::onChanged, this, &KyIcon::updateItem); connect(this, &KyIcon::icontypeChanged, this, &KyIcon::updateItem); + } @@ -52,13 +55,15 @@ void KyIcon::setIcon(const QIcon &icon) void KyIcon::setIconName(const QString &iconName) { - if(!QIcon::hasThemeIcon(iconName)) + m_iconName = iconName; + if(!QIcon::hasThemeIcon(m_iconName)) { m_icon = QIcon(); - qWarning() << "未找到名为 " << iconName << " 的图标!"; + qWarning() << "未找到名为 " << m_iconName << " 的图标!"; return; } - m_icon = QIcon::fromTheme(iconName); + m_icon = QIcon::fromTheme(m_iconName); + emit iconNameChanged(); } void KyIcon::paint(QPainter *painter) diff --git a/ukui-qml-style-helper/KyIcon.h b/ukui-qml-style-helper/KyIcon.h index 836bca0..1ec2f7e 100644 --- a/ukui-qml-style-helper/KyIcon.h +++ b/ukui-qml-style-helper/KyIcon.h @@ -9,7 +9,7 @@ class QStyle; class KyIcon : public QQuickPaintedItem { Q_OBJECT - Q_PROPERTY(QString iconName WRITE setIconName) + Q_PROPERTY(QString iconName READ iconName WRITE setIconName NOTIFY iconNameChanged) Q_PROPERTY(QIcon icon READ icon WRITE setIcon) Q_PROPERTY( bool hover READ hover WRITE setHover NOTIFY hoverChanged) Q_PROPERTY( bool selected READ selected WRITE setSelected NOTIFY selectedChanged) @@ -25,7 +25,7 @@ public: QIcon icon() { return m_icon; } void setIcon(const QIcon &icon); - + QString iconName(){ return m_iconName; } void setIconName(const QString &iconName); bool hover() const { return m_hover; } @@ -72,6 +72,7 @@ Q_SIGNALS: void sunkenChanged(); void onChanged(); void icontypeChanged(); + void iconNameChanged(); protected: bool m_hover; @@ -84,6 +85,7 @@ protected: private: QIcon m_icon; + QString m_iconName; };