QWidgets and QPixmaps and Stylesheets .... oh my.
using QT4.5, I have a class derived from QWidget. It uses stylesheets to loads a bitmap into the background. This stylesheet is loaded at runtime and is user made.
Code:
Q_OBJECT
public:
~MyClass () {}
};
ex from a stylesheet file:
Code:
MyClass {
background-image: url(images/background.png);
}
in my app, I load the stylesheet as runtime using something like:
Code:
QFile file( "thesheet.qss" );
file.
open( QFile::ReadOnly );
qApp->setStyleSheet(styleSheet);
The background loads fine from the stylesheet....
But in my MyClass paintEvent() code, I want to be able to access the QPixmap that the base QWidget class creates for the background (... but it seems that QWidget doesn't provide any accessors.).
I know I can pre-parse the stylesheet to find the image filename, or I could use an inelegant hack and render the widget to a Painter using:
Code:
QPainter_end(Painter);
QPixmap_grabWidget(Widget);
QPainter_begin(Painter);
but isn't there a simple way to access the background image?
Re: QWidgets and QPixmaps and Stylesheets .... oh my.
hmmm.... just noticed QWidget's backgroundRole() method....
Re: QWidgets and QPixmaps and Stylesheets .... oh my.
for the time being I'm using the following
little hack within my myClass code to get the background.
Code:
QBrush bk
= palette.
background();
...
//do some mods on background pixmap, stored in "pm"
...
// redraw the image in QRects defined earlier...
painter.drawPixmap( qr1, pm, qr2 );
still not happy using an ugly hack like this when access to stylesheet defined properties should be easily accessed within the classes themselves...