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:
parent
530c6903a4
commit
244ff33119
@ -64,9 +64,9 @@ void NorwegianWoodStyle::polish(QPalette &palette)
|
|||||||
QColor beige(236, 182, 120);
|
QColor beige(236, 182, 120);
|
||||||
QColor slightlyOpaqueBlack(0, 0, 0, 63);
|
QColor slightlyOpaqueBlack(0, 0, 0, 63);
|
||||||
|
|
||||||
QPixmap backgroundImage(":/images/woodbackground.png");
|
QImage backgroundImage(":/images/woodbackground.png");
|
||||||
QPixmap buttonImage(":/images/woodbutton.png");
|
QImage buttonImage(":/images/woodbutton.png");
|
||||||
QPixmap midImage = buttonImage;
|
QImage midImage = buttonImage.convertToFormat(QImage::Format_RGB32);
|
||||||
|
|
||||||
QPainter painter;
|
QPainter painter;
|
||||||
painter.begin(&midImage);
|
painter.begin(&midImage);
|
||||||
@ -311,11 +311,12 @@ void NorwegianWoodStyle::drawControl(ControlElement element,
|
|||||||
//! [37]
|
//! [37]
|
||||||
void NorwegianWoodStyle::setTexture(QPalette &palette, QPalette::ColorRole role,
|
void NorwegianWoodStyle::setTexture(QPalette &palette, QPalette::ColorRole role,
|
||||||
//! [37] //! [38]
|
//! [37] //! [38]
|
||||||
const QPixmap &pixmap)
|
const QImage &image)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < QPalette::NColorGroups; ++i) {
|
for (int i = 0; i < QPalette::NColorGroups; ++i) {
|
||||||
QColor color = palette.brush(QPalette::ColorGroup(i), role).color();
|
QBrush brush(image);
|
||||||
palette.setBrush(QPalette::ColorGroup(i), role, QBrush(color, pixmap));
|
brush.setColor(palette.brush(QPalette::ColorGroup(i), role).color());
|
||||||
|
palette.setBrush(QPalette::ColorGroup(i), role, brush);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//! [38]
|
//! [38]
|
||||||
|
@ -80,7 +80,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
static void setTexture(QPalette &palette, QPalette::ColorRole role,
|
static void setTexture(QPalette &palette, QPalette::ColorRole role,
|
||||||
const QPixmap &pixmap);
|
const QImage &image);
|
||||||
static QPainterPath roundRectPath(const QRect &rect);
|
static QPainterPath roundRectPath(const QRect &rect);
|
||||||
};
|
};
|
||||||
//! [0]
|
//! [0]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user