summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2020-01-06 01:00:08 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2020-01-06 20:13:31 +0000
commit68c30e372b01561e8809fcfa5426ae896da70b8e (patch)
tree68245df2a3616ff0ebf9e132cab0d3c22a586755 /examples
parentbd4a1b98b813dfbbb4a9db35a380bed8dd5f0ce3 (diff)
parent3a010f72b81d530df96bfb04e0dd2f13a527cc18 (diff)
Merge "Merge remote-tracking branch 'origin/5.14' into 5.15"
Diffstat (limited to 'examples')
-rw-r--r--examples/widgets/doc/src/styles.qdoc10
-rw-r--r--examples/widgets/widgets/styles/norwegianwoodstyle.cpp74
-rw-r--r--examples/widgets/widgets/styles/norwegianwoodstyle.h4
3 files changed, 46 insertions, 42 deletions
diff --git a/examples/widgets/doc/src/styles.qdoc b/examples/widgets/doc/src/styles.qdoc
index a3a02768c6..7a7ae20e91 100644
--- a/examples/widgets/doc/src/styles.qdoc
+++ b/examples/widgets/doc/src/styles.qdoc
@@ -85,8 +85,8 @@
\snippet widgets/styles/norwegianwoodstyle.cpp 0
- The \c polish() function is reimplemented from QStyle. It takes a
- QPalette as a reference and adapts the palette to fit the style.
+ The \c standardPalette() function is reimplemented from QStyle.
+ It returns a QPalette with the style's preferred colors and textures.
Most styles don't need to reimplement that function. The
Norwegian Wood style reimplements it to set a "wooden" palette.
@@ -381,7 +381,7 @@
a certain \l{QPalette::ColorRole}{color role}, for all three
\l{QPalette::ColorGroup}{color groups} (active, disabled,
inactive). We used it to initialize the Norwegian Wood palette in
- \c polish(QPalette &).
+ \c standardPalette.
\snippet widgets/styles/norwegianwoodstyle.cpp 39
\snippet widgets/styles/norwegianwoodstyle.cpp 40
@@ -444,10 +444,6 @@
current style's \l{QStyle::standardPalette()}{standard palette}
is used; otherwise, the system's default palette is honored.
- For the Norwegian Wood style, this makes no difference because we
- always override the palette with our own palette in \c
- NorwegianWoodStyle::polish().
-
\snippet widgets/styles/widgetgallery.cpp 9
\snippet widgets/styles/widgetgallery.cpp 10
diff --git a/examples/widgets/widgets/styles/norwegianwoodstyle.cpp b/examples/widgets/widgets/styles/norwegianwoodstyle.cpp
index bbdb626a18..31150cd994 100644
--- a/examples/widgets/widgets/styles/norwegianwoodstyle.cpp
+++ b/examples/widgets/widgets/styles/norwegianwoodstyle.cpp
@@ -62,42 +62,48 @@ NorwegianWoodStyle::NorwegianWoodStyle() :
}
//! [0]
-void NorwegianWoodStyle::polish(QPalette &palette)
+QPalette NorwegianWoodStyle::standardPalette() const
{
- QColor brown(212, 140, 95);
- QColor beige(236, 182, 120);
- QColor slightlyOpaqueBlack(0, 0, 0, 63);
-
- QImage backgroundImage(":/images/woodbackground.png");
- QImage buttonImage(":/images/woodbutton.png");
- QImage midImage = buttonImage.convertToFormat(QImage::Format_RGB32);
-
- QPainter painter;
- painter.begin(&midImage);
- painter.setPen(Qt::NoPen);
- painter.fillRect(midImage.rect(), slightlyOpaqueBlack);
- painter.end();
-//! [0]
+ if (!m_standardPalette.isBrushSet(QPalette::Disabled, QPalette::Mid)) {
+ QColor brown(212, 140, 95);
+ QColor beige(236, 182, 120);
+ QColor slightlyOpaqueBlack(0, 0, 0, 63);
+
+ QImage backgroundImage(":/images/woodbackground.png");
+ QImage buttonImage(":/images/woodbutton.png");
+ QImage midImage = buttonImage.convertToFormat(QImage::Format_RGB32);
+
+ QPainter painter;
+ painter.begin(&midImage);
+ painter.setPen(Qt::NoPen);
+ painter.fillRect(midImage.rect(), slightlyOpaqueBlack);
+ painter.end();
+ //! [0]
+
+ //! [1]
+ QPalette palette(brown);
+
+ palette.setBrush(QPalette::BrightText, Qt::white);
+ palette.setBrush(QPalette::Base, beige);
+ palette.setBrush(QPalette::Highlight, Qt::darkGreen);
+ setTexture(palette, QPalette::Button, buttonImage);
+ setTexture(palette, QPalette::Mid, midImage);
+ setTexture(palette, QPalette::Window, backgroundImage);
+
+ QBrush brush = palette.window();
+ brush.setColor(brush.color().darker());
+
+ palette.setBrush(QPalette::Disabled, QPalette::WindowText, brush);
+ palette.setBrush(QPalette::Disabled, QPalette::Text, brush);
+ palette.setBrush(QPalette::Disabled, QPalette::ButtonText, brush);
+ palette.setBrush(QPalette::Disabled, QPalette::Base, brush);
+ palette.setBrush(QPalette::Disabled, QPalette::Button, brush);
+ palette.setBrush(QPalette::Disabled, QPalette::Mid, brush);
+
+ m_standardPalette = palette;
+ }
-//! [1]
- palette = QPalette(brown);
-
- palette.setBrush(QPalette::BrightText, Qt::white);
- palette.setBrush(QPalette::Base, beige);
- palette.setBrush(QPalette::Highlight, Qt::darkGreen);
- setTexture(palette, QPalette::Button, buttonImage);
- setTexture(palette, QPalette::Mid, midImage);
- setTexture(palette, QPalette::Window, backgroundImage);
-
- QBrush brush = palette.window();
- brush.setColor(brush.color().darker());
-
- palette.setBrush(QPalette::Disabled, QPalette::WindowText, brush);
- palette.setBrush(QPalette::Disabled, QPalette::Text, brush);
- palette.setBrush(QPalette::Disabled, QPalette::ButtonText, brush);
- palette.setBrush(QPalette::Disabled, QPalette::Base, brush);
- palette.setBrush(QPalette::Disabled, QPalette::Button, brush);
- palette.setBrush(QPalette::Disabled, QPalette::Mid, brush);
+ return m_standardPalette;
}
//! [1]
diff --git a/examples/widgets/widgets/styles/norwegianwoodstyle.h b/examples/widgets/widgets/styles/norwegianwoodstyle.h
index 5a1783eb4d..62ca502d05 100644
--- a/examples/widgets/widgets/styles/norwegianwoodstyle.h
+++ b/examples/widgets/widgets/styles/norwegianwoodstyle.h
@@ -66,7 +66,8 @@ class NorwegianWoodStyle : public QProxyStyle
public:
NorwegianWoodStyle();
- void polish(QPalette &palette) override;
+ QPalette standardPalette() const override;
+
void polish(QWidget *widget) override;
void unpolish(QWidget *widget) override;
int pixelMetric(PixelMetric metric, const QStyleOption *option,
@@ -82,6 +83,7 @@ private:
static void setTexture(QPalette &palette, QPalette::ColorRole role,
const QImage &image);
static QPainterPath roundRectPath(const QRect &rect);
+ mutable QPalette m_standardPalette;
};
//! [0]