steb
5th June 2009, 04:01
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.
class MyClass : public QWidget
Q_OBJECT
public:
MyClass (QWidget *pParent ) : QWidget( pParent) {}
~MyClass () {}
virtual void paintEvent(QPaintEvent *ev);
};
ex from a stylesheet file:
MyClass {
background-image: url(images/background.png);
}
in my app, I load the stylesheet as runtime using something like:
QFile file( "thesheet.qss" );
file.open( QFile::ReadOnly );
QString styleSheet = QLatin1String( file.readAll() );
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:
QPainter_end(Painter);
QPixmap_grabWidget(Widget);
QPainter_begin(Painter);
but isn't there a simple way to access the background image?
class MyClass : public QWidget
Q_OBJECT
public:
MyClass (QWidget *pParent ) : QWidget( pParent) {}
~MyClass () {}
virtual void paintEvent(QPaintEvent *ev);
};
ex from a stylesheet file:
MyClass {
background-image: url(images/background.png);
}
in my app, I load the stylesheet as runtime using something like:
QFile file( "thesheet.qss" );
file.open( QFile::ReadOnly );
QString styleSheet = QLatin1String( file.readAll() );
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:
QPainter_end(Painter);
QPixmap_grabWidget(Widget);
QPainter_begin(Painter);
but isn't there a simple way to access the background image?