PDA

View Full Version : [QT4.1.1 XP] background image



incapacitant
26th February 2006, 13:35
I try to set the background of a widget to an image as indicated in Assistant in the
Porting to QT4 of setPaletteBackgroundPixmap :


QWidget *widget = new QWidget;
QPixmap pixmap(":/images/bArchi.png");
QPalette palette;
palette.setBrush(widget->backgroundRole(), QBrush(pixmap));
widget->setPalette(palette);
setCentralWidget(widget);


I played around with many combinations of the above code, but nothing will show my
image. The background remains unchanged...

:confused:

wysota
26th February 2006, 13:44
Is the path to the resource image correct? Try using a file path (preferrably non-relative one) first.

incapacitant
26th February 2006, 15:04
QPixmap pixmap("C:/Qt/test/chart/images/bArchi.png");


Unfortunately the absolute path has the same negative result.
:o

incapacitant
1st March 2006, 13:02
correct answer was simple but took me a while to find it :
to change this window's background :



QPalette palette;
QPixmap pixmap = QPixmap("./images/bBackground.png");
palette.setBrush((this)->backgroundRole(), QBrush(pixmap));
(this)->setPalette(palette);



:)