[plasma/union] src/output/qtquick/plugin: output/quick: Forward style change events from 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 33146516c14b938c1aa113ee4e0f3788b86d8a9a by Arjen Hiemstra.
Committed on 05/08/2026 at 11:09.
Pushed by ahiemstra into branch 'master'.

output/quick: Forward style change events from QuickElement

This removes the need for QuickStyle to install an event listener on the
style of its element, which makes things simpler when an element's style
changes.

M  +16   -0    src/output/qtquick/plugin/QuickElement.cpp
M  +0    -2    src/output/qtquick/plugin/QuickStyle.cpp

https://invent.kde.org/plasma/union/-/commit/33146516c14b938c1aa113ee4e0f3788b86d8a9a

diff --git a/src/output/qtquick/plugin/QuickElement.cpp b/src/output/qtquick/plugin/QuickElement.cpp
index 9c92f953..09b42ce8 100644
--- a/src/output/qtquick/plugin/QuickElement.cpp
+++ b/src/output/qtquick/plugin/QuickElement.cpp
@@ -299,6 +299,8 @@ QuickElement::QuickElement(QObject *parent)
     m_element = Element::create();
     m_element->installEventFilter(this);
 
+    StyleRegistry::instance()->platform()->installEventFilter(this);
+
     m_statesGroup = std::make_unique<StatesGroup>(this);
 
     initialize();
@@ -417,6 +419,14 @@ bool QuickElement::eventFilter(QObject *watched, QEvent *event)
         return false;
     }
 
+    if (event->type() == StyleChangedEvent::s_type) {
+        // Forward style changes so that other objects (QuickStyle) filtering
+        // this do not need to install their own event filter on a style that
+        // might change.
+        QCoreApplication::sendEvent(this, event);
+        return false;
+    }
+
     return QObject::eventFilter(watched, event);
 }
 
@@ -468,6 +478,10 @@ void QuickElement::setActiveStates(Union::Element::States newActiveStates)
 
 void QuickElement::setStyle(const std::shared_ptr<Union::Style> &newStyle)
 {
+    if (m_style) {
+        m_style->removeEventFilter(this);
+    }
+
     m_style = newStyle;
 
     if (!m_style) {
@@ -484,6 +498,8 @@ void QuickElement::setStyle(const std::shared_ptr<Union::Style> &newStyle)
         }
     }
 
+    m_style->installEventFilter(this);
+
     const auto children = attachedChildren();
     for (const auto &child : children) {
         qobject_cast<QuickElement *>(child)->updateStyleFromParent();
diff --git a/src/output/qtquick/plugin/QuickStyle.cpp b/src/output/qtquick/plugin/QuickStyle.cpp
index e83bacef..47c8815c 100644
--- a/src/output/qtquick/plugin/QuickStyle.cpp
+++ b/src/output/qtquick/plugin/QuickStyle.cpp
@@ -101,14 +101,12 @@ void QuickStyle::setElement(QuickElement *newElement)
 
     if (m_element) {
         m_element->removeEventFilter(this);
-        m_element->style()->removeEventFilter(this);
     }
 
     m_element = newElement;
 
     if (m_element) {
         m_element->installEventFilter(this);
-        m_element->style()->installEventFilter(this);
     }
 }