Pregunta

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

Pero el widget no muestra ninguna imagen.

¿Fue útil?

Solución

¿Estás tratando de mostrar la imagen escalada en un widget? No creo que configurar la imagen en el pincel y luego configurar el pincel en la paleta sea el enfoque correcto.

Puede usar un Qlabel para mostrar una imagen en un widget. Como esto:

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

QLabel *label = new QLabel(this);
label->setPixmap(scaled);

Otros consejos

Estás mostrando el widget antes de configurar la paleta. Intente configurar la paleta primero.

Si eso no ayuda, intente especificar la ruta del archivo completo.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top