PDA

View Full Version : Background image on a combined widget list



buffer
17th November 2010, 22:03
Hi, i'm trying to set a background image on a combined QWidget using stylesheets.
For combined QWidget i mean a qwidget A in which there is a layout containing some widgets, for example:

I have the class A that extends QWidget, in te constructor i have the following code to create a combined widget:

hLayout = new QHBoxLayout;
vLayout = new QVBoxLayout;

labelGroup->adjustSize();
labelIco->adjustSize();
labelIcoReceived->adjustSize();
labelTxt->adjustSize();
labelTime->adjustSize();

hLayout->addWidget(labelIcoReceived);
hLayout->addWidget(labelGroup);
hLayout->addWidget(labelIco);
hLayout->addWidget(labelService);
hLayout->addWidget(labelTime);
vLayout->addLayout(hLayout);
vLayout->addWidget(labelTxt);

setLayout(vLayout);
setSizePolicy(QSizePolicy::Expanding,QSizePolicy:: Minimum);
adjustSize();

If i try to append


setStyleSheet("background-color: yellow");

The result is the following:

5477

And obviously i don't want this, i wan't to spread the color all over the widget.
I would like to use stylesheets because i wan't to add a scalable border image to the background like the one explained here (http://doc.trolltech.com/qq/qq20-qss.html) and showed here:
http://doc.trolltech.com/qq/qq20-borderimage.png

How can i do this?

Thanks!

Lykurg
17th November 2010, 22:19
It is most likely you have to set setAutoFillBackground to true. Then it should work. Also you might want to set the style sheet only for the widget, not for all children also.

buffer
18th November 2010, 00:04
Solved!
I have modified my qwidget A declaration, making it extends QFrame instead of QWidget and then using:


setStyleSheet("A{ background-color: yellow }"); in order not to propagate the style to children.

Thanks

P.S. This site (http://ahmadferdous.blogspot.com/2009/05/qt-set-background-image-of-custom.html) helps to overcome these kind of problems. It explains how to set backgrounds on widgets of frames.