Hello,
I've created a widget and I want to have an image on its background. But when I try to do it, the image is also draw on each child widget.
I've tried with designer but It doesn't work either.
I've been able to not drawing again the image on the child widgets, drawing a new image on them.
I'll paste the code and show you some shoots.
#include <QApplication>
#include <QListWidget>
#include <QGridLayout>
#include <QWidget>
int main(int argc, char ** argv)
{
widget.setStyleSheet("background-image: url(/home/asier/imagenes/fondos/14999-Midsommarblomster.jpg)");
leftLayout->setSpacing (0);
for( int row = 0; row < 2; row++ ) {
for( int col = 0; col < 2; col++ ) {
wi->setStyleSheet("background-image: url(/home/asier/imagenes/fondos/Abetal.jpg);background-attachment: fixed");
leftLayout->addWidget( wi, row +1, col );
leftLayout->setRowStretch( row + 1, 1 );
}
}
widget.setLayout(leftLayout);
widget.show();
return app.exec();
}
#include <QApplication>
#include <QListWidget>
#include <QGridLayout>
#include <QWidget>
int main(int argc, char ** argv)
{
QApplication app( argc, argv );
QWidget widget(0);
widget.setStyleSheet("background-image: url(/home/asier/imagenes/fondos/14999-Midsommarblomster.jpg)");
QGridLayout *leftLayout = new QGridLayout();
leftLayout->setSpacing (0);
for( int row = 0; row < 2; row++ ) {
for( int col = 0; col < 2; col++ ) {
QListWidget *wi = new QListWidget();
wi->setStyleSheet("background-image: url(/home/asier/imagenes/fondos/Abetal.jpg);background-attachment: fixed");
leftLayout->addWidget( wi, row +1, col );
leftLayout->setRowStretch( row + 1, 1 );
}
}
widget.setLayout(leftLayout);
widget.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
In the first shoot you can be how the image is also drawn on each widget, the second shows the image on the background, but with a new one for each widget. And the last one, shows the desinger with blank widgets, but the preview draws again the image for each of them.
What can I do to have the image on the background, and not on each widget?
I don't know if It is my fault, is not implemented or if it is a bug?
Thank you in advance!
Asier
Bookmarks