PDA

View Full Version : background-image on QLabel does NOT work



VireX
7th June 2007, 21:41
QLabel#logo {
color: red;
background-image: url(folder/logobackground.png);
background-repeat: repeat-x;
background-origin: content;
}

Ok I have a QLabel with ObjectName as "logo".
I set the QLabel text to "boooooooooooooo" or some random text.
Also keeping in mind that minimum size for this QLabel is 400 pixels wide.
Now In CSS this would print logobackground.png on the QLabel about as many times as it can fit on the X-axis.

However, after 2 hours of struggling, I find that QLabel does NOT support background-image, and the documentation must have a typo or something.

I checked if it can find folder/logobackground.png at least 5 times so don't tell me I have wrong paths. I checked to make sure the Object name is there... in fact, the "boooooo" text does indeed become RED. But it seems QLabel does not support background-image attribute.

And Just to prove to anyone who doubts my competence in being able to get the paths right etc here is a small application for you to try that proves that QLabel does not support background-image:


QApplication app(argc, argv);

QLabel hello("Hello world!");
hello.setObjectName("lol");
app.setStyleSheet(QString("QLabel#logo { background-image: url(logobackground.png); }"));
hello.resize(500, 80);

hello.show();

jpn
8th June 2007, 08:25
Could this (http://doc.trolltech.com/4.2/stylesheet#list-of-stylable-widgets) be the problem:


For QFrame and its subclasses, you must set the QFrame::frameStyle property to QFrame::StyledPanel; otherwise, the background and border attributes will not be respected.

?

VireX
8th June 2007, 20:30
Yes I found that after 3 hours of trying several things... Really really dumb of them to do this and not document that properly. It should be written clearly next to QLabel in stylesheet.html