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.
Q_OBJECT
public:
~MyClass () {}
};
class MyClass : public QWidget
Q_OBJECT
public:
MyClass (QWidget *pParent ) : QWidget( pParent) {}
~MyClass () {}
virtual void paintEvent(QPaintEvent *ev);
};
To copy to clipboard, switch view to plain text mode
ex from a stylesheet file:
MyClass {
background-image: url(images/background.png);
}
MyClass {
background-image: url(images/background.png);
}
To copy to clipboard, switch view to plain text mode
in my app, I load the stylesheet as runtime using something like:
QFile file( "thesheet.qss" );
file.
open( QFile::ReadOnly );
qApp->setStyleSheet(styleSheet);
QFile file( "thesheet.qss" );
file.open( QFile::ReadOnly );
QString styleSheet = QLatin1String( file.readAll() );
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:
QPainter_end(Painter);
QPixmap_grabWidget(Widget);
QPainter_begin(Painter);
QPainter_end(Painter);
QPixmap_grabWidget(Widget);
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?
Bookmarks