PDA

View Full Version : QStyleSheets: background position using pixels problem



GuS
25th May 2011, 19:01
Hi guys,

Recently I've started to implement CSS sprite method in my Application Skinning (which uses QStyleSheets). In many cases, i use border-image for positioning those images and styling a widget (like QPushButton and widgets that are no fixed, so that background could be stretched).
Now, in other hand i have fixed widgets, in which case i used to use background property in the css style. Since i want to migrate those to CSS sprite method as well, I found that i cant (does not work or i am doing it wrong) specidy the position of the image inside the sprite with pixels (it works when you use top, center, left, etc. but not when you use pixels as the position of the background-position).

Here is my example:



QPushButton#minimizeWindowButton {
border: 0;
background: url(windowButtons.png) -0px 0px;
width: 20px;
height: 20px;
}
QPushButton#minimizeWindowButton:hover {
background: url(windowButtons.png) -20px 0px;
}
QPushButton#minimizeWindowButton:pressed {
background: url(windowButtons.png) -40px 0px;
}
QPushButton#closeWindowButton {
border: 0;
background: url(windowButtons.png) -60px 0px;
width: 20px;
height: 20px;
}
QPushButton#closeWindowButton:hover {
background: url(windowButtons.png) -80px 0px;
}
QPushButton#closeWindowButton:pressed {
background: url(windowButtons.png) -100px 0px;
}


This does not work, in both buttons shows the same image and the hover and pressed does not exist.
Now, this works perfectly if I use border-image. Also, you see changes if you use positions properties like top, middle, center, etc. But in this case, is not useful since i need to specify the position in pixels.

Any Idea? Does Qt does not support it?

I am attaching the .ui (which includes the stylesheet already) and the sprite image if someone want to test. Just have in mind to change the image path of the sprite.

Thanks in advance.

Cheers.