문제

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.

도움이 되었습니까?

해결책

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);

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top