3 Attachment(s)
background-image on a set of widgets
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.
Code:
#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();
}
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
Re: background-image on a set of widgets
Hi,
I think this may be help you.
Better to go for QLabel.you will get any kind of image as back ground.You can set a Qpixmap on Each label prosperity in your each widget on designer itself.
Re: background-image on a set of widgets
Hi, Thanks.
But I need QListViews, I need lists.
The only problem is that the whole widget background-image is repetated again on each child widget.
I mean, Transparents Lists that woul make possible to view the image that is in the background.
1 Attachment(s)
Re: background-image on a set of widgets
I've solved it.
I don't think this is the best way, but it works.
As I noticed that when I draw a background on the widgets, the Whole background was not draw on them, I've set a transparent background image for the widgets and It does the trick.
Code:
wi->setStyleSheet("background-image: url(/home/asier/transparent.png)");
Now I've to adapt it to a more complex widget. That at the first try does not work. But I hope, it will.
If you have any other idea for doing this, please tell me.
Thanks
Re: background-image on a set of widgets
It would have been easier using http://doc.qt.nokia.com/4.7-snapshot...ackground-prop. Widgets don't draw their background for performance reasons. Setting a stylesheet will automaticall turn this on for my knowledge.