aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2016-08-23 16:33:21 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-09-02 14:40:34 +0000
commit33904b63ce9971efc3763a0048a084ec3324dfc4 (patch)
treee2ad51da97a0a904bda0304659bdc618e95ed877
parentc8372be0b96b1aaa9f8cb8737f8d4a662252d446 (diff)
Material: ignore Material.background unless explicitly set
Doing Material.background: "red" in an ApplicationWindow shouldn't affect the background color of e.g. a Button. The background property should still propagate though, so we change buttonColor() to ignore the value of background if it wasn't explicitly set. Change-Id: I09b4df142935b19de35a77bd68c6c062417b74fc Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
-rw-r--r--src/imports/controls/material/qquickmaterialstyle.cpp3
-rw-r--r--tests/auto/qquickmaterialstyle/data/tst_material.qml29
2 files changed, 31 insertions, 1 deletions
diff --git a/src/imports/controls/material/qquickmaterialstyle.cpp b/src/imports/controls/material/qquickmaterialstyle.cpp
index bc53695a..8562cdbb 100644
--- a/src/imports/controls/material/qquickmaterialstyle.cpp
+++ b/src/imports/controls/material/qquickmaterialstyle.cpp
@@ -716,6 +716,7 @@ void QQuickMaterialStyle::setBackground(const QVariant &var)
m_background = background;
propagateBackground();
emit backgroundChanged();
+ emit paletteChanged();
}
void QQuickMaterialStyle::inheritBackground(uint background, bool custom, bool has)
@@ -865,7 +866,7 @@ QColor QQuickMaterialStyle::buttonColor(bool highlighted, bool pressed, bool hov
QColor color = Qt::transparent;
- if (m_hasBackground) {
+ if (m_explicitBackground) {
color = backgroundColor(shade);
} else if (highlighted) {
color = accentColor(shade);
diff --git a/tests/auto/qquickmaterialstyle/data/tst_material.qml b/tests/auto/qquickmaterialstyle/data/tst_material.qml
index 7305b732..1cd1d16d 100644
--- a/tests/auto/qquickmaterialstyle/data/tst_material.qml
+++ b/tests/auto/qquickmaterialstyle/data/tst_material.qml
@@ -74,6 +74,11 @@ TestCase {
}
Component {
+ id: applicationWindow
+ ApplicationWindow { }
+ }
+
+ Component {
id: styledWindow
Window {
Material.theme: Material.Dark
@@ -600,4 +605,28 @@ TestCase {
window.destroy()
}
+
+ function test_buttonBackground() {
+ var appWindow = applicationWindow.createObject(testCase)
+ verify(appWindow)
+ appWindow.visible = true
+
+ var childButton = button.createObject(appWindow)
+ verify(childButton)
+
+ var buttonBackgroundColor = childButton.background.color
+ appWindow.Material.background = "red"
+ // We wait the length of the color animation to be sure that it hasn't actually changed.
+ wait(400)
+ // We want childButton.Material.background to be equal to appWindow.Material.background,
+ // because we want the color to propagate to items that might actually use it...
+ // but Button doesn't use the background color unless explicitly set,
+ // so we compare the actual background rect color instead.
+ compare(childButton.background.color, buttonBackgroundColor)
+
+ childButton.Material.background = "#0000ff"
+ tryCompare(childButton.background, "color", "#0000ff")
+
+ appWindow.destroy()
+ }
}