What does "didn't work" mean in this situation? What was the widget you were trying to apply the image on?
I tried the following code but in vain.
Qt Code:
setAutoFillBackground(true); //QPalette palette = this->palette(); QPalette palette; this->setPalette(palette);To copy to clipboard, switch view to plain text mode
I tried with stylesheet but doing so caused the child widgets (buttons, labels) inherit the background image. So it's not suitable for my need.
Qt Code:
setStyleSheet("background-image: url(:/Resources/topGradient.png);");To copy to clipboard, switch view to plain text mode
Can you please tell me why the use of QPalette for setting background image did not work?
Thanks.
What does "didn't work" mean in this situation? What was the widget you were trying to apply the image on?
Your biological and technological distinctiveness will be added to our own. Resistance is futile.
Please ask Qt related questions on the forum and not using private messages or visitor messages.
wwWidgets - a set of Qt widgets for your applications
I meant by "didn't work" that the intended background image didn't show up.
I'm trying to apply it on my custom widget which inherits a QWidget.
Stylesheets won't work then and as for changing the palette, do you actually paint the background in your widget's paintEvent?
Your biological and technological distinctiveness will be added to our own. Resistance is futile.
Please ask Qt related questions on the forum and not using private messages or visitor messages.
wwWidgets - a set of Qt widgets for your applications
No. I didn't override paintEvent() method. Isn't palette change supposed to serve the purpose? I'm really confused.
Not sure if it's necessary in your case, but maybe: have a .qrc file? Image & path correctly listed there?
Yes. Images and path to images are correctly listed in a .qrc file.
When I tried with overriding paintEvent(), the background image is shown. It seems that custom derived classes of QWidget can't have background image through the use of QPalette. Can anyone please verify my guess?
Times ago there was a problem: http://www.qtsoftware.com/developer/...ntry&id=166742. Now it's still back. The problem is, that the background is drawn (show your widget alone and resize it: for a short time you can see your image), but then it is covered by the background color. May you want to report this...
Working solution with style sheets:Qt Code:
#ifndef MYWIDGET_H #define MYWIDGET_H #include <QtGui> { public: MyWidget() {} protected: { QStyleOption opt; opt.init(this); } }; #endif // MYWIDGET_H int main(int argc, char *argv[]) { MyWidget *w = new MyWidget(); w->setStyleSheet("background-image: url(...);"); w->show(); return a.exec(); }To copy to clipboard, switch view to plain text mode
Ferdous (3rd May 2009)
Thanks! Now I can use stylesheet for setting background-image of a custom widget![]()
Bookmarks