4
QPixmap pic("../image.jpg");

setAutoFillBackground(true);
QPalette palette;
QPixmap scaled=pic.scaled ( 800, 480, Qt::IgnoreAspectRatio, Qt::FastTransformation );

palette.setBrush(QPalette::Window, QBrush(scaled));

//this->setPalette(palette);
QWidget *w= new QWidget(this);
w->setGeometry(0,0,800,480);
w->show();
w->setPalette(palette); 

But the widget does not show any image.

Bart
  • 19,692
  • 7
  • 68
  • 77
Thorin
  • 2,004
  • 1
  • 19
  • 30

2 Answers2

8

Are you just trying to show the scaled image in a widget? I don't think setting the image in the brush and then setting the brush in the palette is the correct approach.

You can just use a QLabel to show an image in a widget. Like this:

QPixmap pic("../image.png");
QPixmap scaled=pic.scaled ( 800, 480, Qt::IgnoreAspectRatio, Qt::FastTransformation );

QLabel *label = new QLabel(this);
label->setPixmap(scaled);
Dusty Campbell
  • 3,146
  • 31
  • 34
  • but i want show some Qpushbuttons to widget when i used label button not working (becaose label are overlap the buttons) so i am try to show image as backgroung through widget – Thorin Jan 11 '12 at 06:57
  • if you just want to change the background check this question: http://stackoverflow.com/q/6406940/2174 – Dusty Campbell Jan 11 '12 at 20:44
0

You are showing the widget before setting the palette. Try setting the palette first.

If that does not help, try specifying the full file path.

mskfisher
  • 3,291
  • 4
  • 35
  • 48