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.

Qt Code:
  1. class MyClass : public QWidget
  2. Q_OBJECT
  3. public:
  4. MyClass (QWidget *pParent ) : QWidget( pParent) {}
  5. ~MyClass () {}
  6. virtual void paintEvent(QPaintEvent *ev);
  7. };
To copy to clipboard, switch view to plain text mode 


ex from a stylesheet file:
Qt Code:
  1. MyClass {
  2. background-image: url(images/background.png);
  3. }
To copy to clipboard, switch view to plain text mode 



in my app, I load the stylesheet as runtime using something like:
Qt Code:
  1. QFile file( "thesheet.qss" );
  2. file.open( QFile::ReadOnly );
  3. QString styleSheet = QLatin1String( file.readAll() );
  4. qApp->setStyleSheet(styleSheet);
To copy to clipboard, switch view to plain text mode 


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:
Qt Code:
  1. QPainter_end(Painter);
  2. QPixmap_grabWidget(Widget);
  3. QPainter_begin(Painter);
To copy to clipboard, switch view to plain text mode 


but isn't there a simple way to access the background image?