[plasma/union] src/output/qtquick/plugin: output/quick: Inherit style from parent unless there is no parent
Arjen Hiemstra <[email protected]> Wed, 5 Aug 2026 11:15:06 +0000 (UTC)
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 44bec75315f00f28e8705d4a60b041cf72555640 by Arjen Hiemstra.
Committed on 05/08/2026 at 11:09.
Pushed by ahiemstra into branch 'master'.
output/quick: Inherit style from parent unless there is no parent
This prepares things for overriding the style for specific elements.
M +38 -3 src/output/qtquick/plugin/QuickElement.cpp
M +6 -2 src/output/qtquick/plugin/QuickElement.h
https://invent.kde.org/plasma/union/-/commit/44bec75315f00f28e8705d4a60b041cf72555640
diff --git a/src/output/qtquick/plugin/QuickElement.cpp b/src/output/qtquick/plugin/QuickElement.cpp
index 53f647ed..9c92f953 100644
--- a/src/output/qtquick/plugin/QuickElement.cpp
+++ b/src/output/qtquick/plugin/QuickElement.cpp
@@ -300,13 +300,17 @@ QuickElement::QuickElement(QObject *parent)
m_element->installEventFilter(this);
m_statesGroup = std::make_unique<StatesGroup>(this);
- m_style = StyleRegistry::instance()->defaultStyle();
initialize();
update();
}
+std::shared_ptr<Union::Style> QuickElement::style() const
+{
+ return m_style;
+}
+
QString QuickElement::type() const
{
return m_element->type();
@@ -385,6 +389,7 @@ QuickElement *QuickElement::qmlAttachedProperties(QObject *parent)
void QuickElement::attachedParentChange(QQuickAttachedPropertyPropagator *, QQuickAttachedPropertyPropagator *)
{
+ updateStyleFromParent();
update();
}
@@ -423,6 +428,10 @@ void QuickElement::componentComplete()
{
m_completed = true;
+ if (!m_style) {
+ setStyle(nullptr);
+ }
+
// Add the window this element belongs to to WindowHandler so it can update
// it to include any required state changes. This is done here because we
// need a hook that is both late enoguh for most of the window stuff to
@@ -457,9 +466,28 @@ void QuickElement::setActiveStates(Union::Element::States newActiveStates)
m_element->setStates(newActiveStates);
}
-std::shared_ptr<Union::Style> QuickElement::style() const
+void QuickElement::setStyle(const std::shared_ptr<Union::Style> &newStyle)
{
- return m_style;
+ m_style = newStyle;
+
+ if (!m_style) {
+ if (attachedParent()) {
+ auto attached = qobject_cast<QuickElement *>(attachedParent());
+ while (attached && !m_style) {
+ m_style = attached->style();
+ attached = qobject_cast<QuickElement *>(attached->attachedParent());
+ }
+ }
+
+ if (!m_style) {
+ m_style = StyleRegistry::instance()->defaultStyle();
+ }
+ }
+
+ const auto children = attachedChildren();
+ for (const auto &child : children) {
+ qobject_cast<QuickElement *>(child)->updateStyleFromParent();
+ }
}
void QuickElement::updateHints()
@@ -537,6 +565,13 @@ void QuickElement::update()
}
}
+void Quick::QuickElement::updateStyleFromParent()
+{
+ if (m_styleName.isEmpty() && attachedParent()) {
+ setStyle(qobject_cast<QuickElement *>(attachedParent())->style());
+ }
+}
+
QuickElementUpdatedEvent::QuickElementUpdatedEvent()
: QEvent(QuickElementUpdatedEvent::s_type)
{
diff --git a/src/output/qtquick/plugin/QuickElement.h b/src/output/qtquick/plugin/QuickElement.h
index ba2b32cb..18165b11 100644
--- a/src/output/qtquick/plugin/QuickElement.h
+++ b/src/output/qtquick/plugin/QuickElement.h
@@ -332,6 +332,8 @@ public:
Q_PROPERTY(QuickElement *parentElement READ parentElement NOTIFY updated)
QuickElement *parentElement() const;
+ std::shared_ptr<Union::Style> style() const;
+
/*!
* \qmlattachedproperty string Element::type
*
@@ -425,8 +427,6 @@ public:
static QuickElement *qmlAttachedProperties(QObject *parent);
- std::shared_ptr<Union::Style> style() const;
-
void componentComplete() override;
protected:
@@ -441,9 +441,11 @@ private:
friend class ElementAttribute;
void setActiveStates(Union::Element::States newActiveStates);
+ void setStyle(const std::shared_ptr<Union::Style> &newStyle);
void updateHints();
void updateAttributes();
void update();
+ void updateStyleFromParent();
std::shared_ptr<Union::Element> m_element;
std::unique_ptr<StatesGroup> m_statesGroup;
@@ -452,6 +454,8 @@ private:
QList<ElementAttribute *> m_attributes;
std::unique_ptr<Union::ElementQuery> m_query;
+
+ QString m_styleName;
std::shared_ptr<Union::Style> m_style;
bool m_completed = false;