styles example: Use QImage instead of QPixmap in NorwegianWoodStyle

Using QImage allows creating the style before the application has
been created, and is the more modern API.

No changes to the documentation needed.

Change-Id: Ifa0e5fa1113802fca18fbd45bb3c0a5ba1dbfeab
Reviewed-by: Andreas Aardal Hanssen <andreas@hanssen.name>
This commit is contained in:
Tor Arne Vestbø 2019-06-20 14:47:12 +02:00
parent 530c6903a4
commit 244ff33119
2 changed files with 8 additions and 7 deletions

View File

@ -64,9 +64,9 @@ void NorwegianWoodStyle::polish(QPalette &palette)
QColor beige(236, 182, 120);
QColor slightlyOpaqueBlack(0, 0, 0, 63);
QPixmap backgroundImage(":/images/woodbackground.png");
QPixmap buttonImage(":/images/woodbutton.png");
QPixmap midImage = buttonImage;
QImage backgroundImage(":/images/woodbackground.png");
QImage buttonImage(":/images/woodbutton.png");
QImage midImage = buttonImage.convertToFormat(QImage::Format_RGB32);
QPainter painter;
painter.begin(&midImage);
@ -311,11 +311,12 @@ void NorwegianWoodStyle::drawControl(ControlElement element,
//! [37]
void NorwegianWoodStyle::setTexture(QPalette &palette, QPalette::ColorRole role,
//! [37] //! [38]
const QPixmap &pixmap)
const QImage &image)
{
for (int i = 0; i < QPalette::NColorGroups; ++i) {
QColor color = palette.brush(QPalette::ColorGroup(i), role).color();
palette.setBrush(QPalette::ColorGroup(i), role, QBrush(color, pixmap));
QBrush brush(image);
brush.setColor(palette.brush(QPalette::ColorGroup(i), role).color());
palette.setBrush(QPalette::ColorGroup(i), role, brush);
}
}
//! [38]

View File

@ -80,7 +80,7 @@ public:
private:
static void setTexture(QPalette &palette, QPalette::ColorRole role,
const QPixmap &pixmap);
const QImage &image);
static QPainterPath roundRectPath(const QRect &rect);
};
//! [0]