styles example: Implement standarPalette()
Instead of polishing the (possible) system palette. Makes the checkbox for "Use style's standard palette" actually work for the custom style, and is how styles are supposed to provide their own preferred palette. Change-Id: I3228ef45c023d0d058e48ff0fc14f094367b2008 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
parent
a6f56251ca
commit
05e5306787
@ -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
|
||||
|
||||
|
@ -62,8 +62,9 @@ NorwegianWoodStyle::NorwegianWoodStyle() :
|
||||
}
|
||||
|
||||
//! [0]
|
||||
void NorwegianWoodStyle::polish(QPalette &palette)
|
||||
QPalette NorwegianWoodStyle::standardPalette() const
|
||||
{
|
||||
if (!m_standardPalette.isBrushSet(QPalette::Disabled, QPalette::Mid)) {
|
||||
QColor brown(212, 140, 95);
|
||||
QColor beige(236, 182, 120);
|
||||
QColor slightlyOpaqueBlack(0, 0, 0, 63);
|
||||
@ -77,10 +78,10 @@ void NorwegianWoodStyle::polish(QPalette &palette)
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.fillRect(midImage.rect(), slightlyOpaqueBlack);
|
||||
painter.end();
|
||||
//! [0]
|
||||
//! [0]
|
||||
|
||||
//! [1]
|
||||
palette = QPalette(brown);
|
||||
//! [1]
|
||||
QPalette palette(brown);
|
||||
|
||||
palette.setBrush(QPalette::BrightText, Qt::white);
|
||||
palette.setBrush(QPalette::Base, beige);
|
||||
@ -98,6 +99,11 @@ void NorwegianWoodStyle::polish(QPalette &palette)
|
||||
palette.setBrush(QPalette::Disabled, QPalette::Base, brush);
|
||||
palette.setBrush(QPalette::Disabled, QPalette::Button, brush);
|
||||
palette.setBrush(QPalette::Disabled, QPalette::Mid, brush);
|
||||
|
||||
m_standardPalette = palette;
|
||||
}
|
||||
|
||||
return m_standardPalette;
|
||||
}
|
||||
//! [1]
|
||||
|
||||
|
@ -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]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user