[plasma/union] src/output/qtquick/plugin: output/quick: Allow explicitly setting the style to use for QuickElement

Arjen Hiemstra <[email protected]> Wed, 5 Aug 2026 11:15:06 +0000 (UTC)
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 64449cd113576d69bfda8f1ae9d67e1c3841e2cd by Arjen Hiemstra.
Committed on 05/08/2026 at 11:09.
Pushed by ahiemstra into branch 'master'.

output/quick: Allow explicitly setting the style to use for QuickElement

This will change the style used by QuickElement and all its children
that inherit from it. This allows a subtree of elements to use a
different Union style.

M  +19   -1    src/output/qtquick/plugin/QuickElement.cpp
M  +11   -1    src/output/qtquick/plugin/QuickElement.h

https://invent.kde.org/plasma/union/-/commit/64449cd113576d69bfda8f1ae9d67e1c3841e2cd

diff --git a/src/output/qtquick/plugin/QuickElement.cpp b/src/output/qtquick/plugin/QuickElement.cpp
index 09b42ce8..1470e7f8 100644
--- a/src/output/qtquick/plugin/QuickElement.cpp
+++ b/src/output/qtquick/plugin/QuickElement.cpp
@@ -308,6 +308,24 @@ QuickElement::QuickElement(QObject *parent)
     update();
 }
 
+QString QuickElement::styleId() const
+{
+    return m_styleId;
+}
+
+void QuickElement::setStyleId(const QString &newStyleId)
+{
+    if (newStyleId == m_styleId) {
+        return;
+    }
+
+    m_styleId = newStyleId;
+    setStyle(StyleRegistry::instance()->style(m_styleId));
+    update();
+
+    Q_EMIT styleIdChanged();
+}
+
 std::shared_ptr<Union::Style> QuickElement::style() const
 {
     return m_style;
@@ -583,7 +601,7 @@ void QuickElement::update()
 
 void Quick::QuickElement::updateStyleFromParent()
 {
-    if (m_styleName.isEmpty() && attachedParent()) {
+    if (m_styleId.isEmpty() && attachedParent()) {
         setStyle(qobject_cast<QuickElement *>(attachedParent())->style());
     }
 }
diff --git a/src/output/qtquick/plugin/QuickElement.h b/src/output/qtquick/plugin/QuickElement.h
index 18165b11..c12944b1 100644
--- a/src/output/qtquick/plugin/QuickElement.h
+++ b/src/output/qtquick/plugin/QuickElement.h
@@ -332,6 +332,16 @@ public:
     Q_PROPERTY(QuickElement *parentElement READ parentElement NOTIFY updated)
     QuickElement *parentElement() const;
 
+    /*!
+     * \qmlattachedproperty string Element::style
+     *
+     * The style to use for this element and any children.
+     */
+    Q_PROPERTY(QString styleId READ styleId WRITE setStyleId NOTIFY styleIdChanged)
+    QString styleId() const;
+    void setStyleId(const QString &newStyleId);
+    Q_SIGNAL void styleIdChanged();
+
     std::shared_ptr<Union::Style> style() const;
 
     /*!
@@ -455,7 +465,7 @@ private:
 
     std::unique_ptr<Union::ElementQuery> m_query;
 
-    QString m_styleName;
+    QString m_styleId;
     std::shared_ptr<Union::Style> m_style;
 
     bool m_completed = false;