Originally Posted by
Ferdous
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:
#ifndef MYWIDGET_H
#define MYWIDGET_H
#include <QtGui>
{
public:
MyWidget() {}
protected:
{
opt.init(this);
style
()->drawPrimitive
(QStyle::PE_Widget,
&opt,
&p,
this);
}
};
#endif // MYWIDGET_H
int main(int argc, char *argv[])
{
MyWidget *w = new MyWidget();
w->setStyleSheet("background-image: url(...);");
w->show();
return a.exec();
}
#ifndef MYWIDGET_H
#define MYWIDGET_H
#include <QtGui>
class MyWidget : public QWidget
{
public:
MyWidget() {}
protected:
void paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
};
#endif // MYWIDGET_H
int main(int argc, char *argv[])
{
QApplication a(argc, 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
Bookmarks