PDA

View Full Version : Using .svg images for QPushButton Style sheets



Dreamerzz
20th July 2011, 15:50
I'm tying to use scalable vector graphics for my push button, except two main issues arise when doing so:


0) when setting the push button to the svg, it seems centered on the top left corner for some strange reason
1) when trying to set a mask using the pixmap, it seems that the svg does not scale right at all to the box

this i my svg

<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" width="12cm" height="12cm">
<g style="fill-opacity:0.7; stroke:black; stroke-width:0.1cm;">
<circle cx="6cm" cy="2cm" r="100" style="fill:red;"
transform="translate(0,50)" />
<circle cx="6cm" cy="2cm" r="100" style="fill:blue;"
transform="translate(70,150)" />
<circle cx="6cm" cy="2cm" r="100" style="fill:green;"
transform="translate(-70,150)"/>
</g>
</svg>

and here is my style sheets


QPushButton:enabled{
border-image: url(:/Button1/img1.svg) 4 4 4 4 stretch stretch;
}

here is my masking method


QPixmap pixmap(":/Button1/img1.svg");
ui->pushButton->setMask(pixmap.mask());


Thanks

high_flyer
21st July 2011, 09:44
1) when trying to set a mask using the pixmap, it seems that the svg does not scale right at all to the box
You have to scale your pixmap to the right size before setting the mask.

Dreamerzz
21st July 2011, 15:00
how does one scale the pixmap?

high_flyer
21st July 2011, 15:20
Did you try QPixmap::scaled()?