PDA

View Full Version : QLabel ScaledContents ignored by style sheet?



WinchellChung
26th February 2008, 22:18
I've got a QLabel. I want to display in it imageX.png. I edit the QLabel in Qt Designer.

Say I set the QLabel to a SizePolicy of Fixed Fixed, and I set the geometry, the MaximumSize and the MinimumSize to 50 x 50. Suppose further than imageX.png has a dimension of 100 x 100.

Finally set the QLabel's ScaledContents attribute to True.

If I insert imageX.png into my *.qrc resource file, and set the Pixmap property of my QLabel to use the resource, everything works fine. The image appears as 50 x 50.

However, if I clear the Pixmap property of my QLabel, and connect to the form a *.qss style sheet that sets the QLabel's background-image attribute with a url containing a file path to imageX.png on my hard drive, it does not work. The image appears as 100 x 100, clipped in a 50 x 50 QLabel.

An I doing something wrong? Or do QLabel pixmaps set by style sheets ignore the ScaledContents attribute?

wysota
26th February 2008, 23:00
background-image doesn't scale by itself. It's exactly the same with CSS. The pixmap property of the label and background-image style attribute are two completely different things.

WinchellChung
27th February 2008, 14:32
I don't suppose there is a qss style sheet element that will allow one to change a QLabel's pixmap property, is there?

I didn't think so.

wysota
27th February 2008, 14:50
No, there is nothing like that. But you can use the resource system to fetch the pixmap and simply replace the resource set with another one when you want another graphics set (of course this won't affect existing widgets).