aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-09-30 21:23:01 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-10-02 11:24:01 +0000
commitde0212e51e65b578bc941c1004914a0c33c06da7 (patch)
tree2ecccddc29e5eb9b1ad74a9c2b0371036a47d0eb
parente95dc3b4853c1736aef0ef2cc5248ec0aa46e3ff (diff)
Fix style inheritance
When unable to find a parent item style on window change, use the window style as a fallback to avoid a parentless style. Task-number: QTBUG-52631 Change-Id: I5d31dc72075f06f865f01c3ee2411de6a1485677 Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
-rw-r--r--src/quickcontrols2/qquickstyleattached.cpp7
-rw-r--r--tests/auto/qquickmaterialstyle/data/tst_material.qml19
2 files changed, 21 insertions, 5 deletions
diff --git a/src/quickcontrols2/qquickstyleattached.cpp b/src/quickcontrols2/qquickstyleattached.cpp
index cdfa902e..e72abde0 100644
--- a/src/quickcontrols2/qquickstyleattached.cpp
+++ b/src/quickcontrols2/qquickstyleattached.cpp
@@ -241,10 +241,13 @@ void QQuickStyleAttached::parentStyleChange(QQuickStyleAttached *newParent, QQui
void QQuickStyleAttached::itemWindowChanged(QQuickWindow *window)
{
- Q_UNUSED(window);
+ QQuickStyleAttached *parentStyle = nullptr;
QQuickItem *item = qobject_cast<QQuickItem *>(sender());
if (item)
- setParentStyle(findParentStyle(metaObject(), item));
+ parentStyle = findParentStyle(metaObject(), item);
+ if (!parentStyle)
+ parentStyle = attachedStyle(metaObject(), window);
+ setParentStyle(parentStyle);
}
void QQuickStyleAttached::itemParentChanged(QQuickItem *item, QQuickItem *parent)
diff --git a/tests/auto/qquickmaterialstyle/data/tst_material.qml b/tests/auto/qquickmaterialstyle/data/tst_material.qml
index 5cfec8d3..e1e100d7 100644
--- a/tests/auto/qquickmaterialstyle/data/tst_material.qml
+++ b/tests/auto/qquickmaterialstyle/data/tst_material.qml
@@ -41,6 +41,7 @@
import QtQuick 2.2
import QtQuick.Window 2.2
import QtTest 1.0
+import QtQuick.Templates 2.0 as T
import QtQuick.Controls 2.0
import QtQuick.Controls.Material 2.0
@@ -127,6 +128,7 @@ TestCase {
visible: true
property alias popup: popupInstance
property alias label: labelInstance
+ property alias label2: labelInstance2
Popup {
id: popupInstance
Label {
@@ -136,6 +138,14 @@ TestCase {
}
Component.onCompleted: open()
}
+ T.Popup {
+ contentItem: Label {
+ id: labelInstance2
+ text: "test"
+ color: Material.textSelectionColor
+ }
+ Component.onCompleted: open()
+ }
}
}
@@ -291,16 +301,19 @@ TestCase {
var popupObject = popupComponent.createObject(testCase)
compare(popupObject.popup.Material.textSelectionColor.toString(), popupObject.Material.textSelectionColor.toString())
compare(popupObject.label.color.toString(), popupObject.Material.textSelectionColor.toString())
+ compare(popupObject.label2.color.toString(), popupObject.Material.textSelectionColor.toString())
popupObject.Material[prop] = data.value1
compare(popupObject.Material[prop], data.value1)
compare(popupObject.popup.Material.textSelectionColor.toString(), popupObject.Material.textSelectionColor.toString())
compare(popupObject.label.color.toString(), popupObject.Material.textSelectionColor.toString())
+ compare(popupObject.label2.color.toString(), popupObject.Material.textSelectionColor.toString())
popupObject.Material[prop] = data.value2
compare(popupObject.Material[prop], data.value2)
compare(popupObject.popup.Material.textSelectionColor.toString(), popupObject.Material.textSelectionColor.toString())
compare(popupObject.label.color.toString(), popupObject.Material.textSelectionColor.toString())
+ compare(popupObject.label2.color.toString(), popupObject.Material.textSelectionColor.toString())
popupObject.destroy()
}
@@ -500,11 +513,11 @@ TestCase {
compare(control.Material[prop], "#80808080")
// unknown
- ignoreWarning(Qt.resolvedUrl("tst_material.qml") + ":57:9: QML Button: unknown Material." + prop + " value: 123")
+ ignoreWarning(Qt.resolvedUrl("tst_material.qml") + ":58:9: QML Button: unknown Material." + prop + " value: 123")
control.Material[prop] = 123
- ignoreWarning(Qt.resolvedUrl("tst_material.qml") + ":57:9: QML Button: unknown Material." + prop + " value: foo")
+ ignoreWarning(Qt.resolvedUrl("tst_material.qml") + ":58:9: QML Button: unknown Material." + prop + " value: foo")
control.Material[prop] = "foo"
- ignoreWarning(Qt.resolvedUrl("tst_material.qml") + ":57:9: QML Button: unknown Material." + prop + " value: #1")
+ ignoreWarning(Qt.resolvedUrl("tst_material.qml") + ":58:9: QML Button: unknown Material." + prop + " value: #1")
control.Material[prop] = "#1"
control.destroy()