PDA

View Full Version : QPushButton set width and height from StyleSheet



AL
19th March 2010, 14:03
Hello,
I am loading a background image in a QPushButton and I would like to set the button width and height from the stylesheet with the background image width and height. Is it possible?



QPushButton *btn = new QPushButton("click me",0);
style = "QPushButton { ";
style += "background: url(:/images/btn-orange-normal.png);";
style += "background-repeat: repeat-n; border-width: 0px; border-style: none;";

/*
I would like to add something like:
style += "width: background.width; height: background.height"
*/

style += "}";
btn->setStyleSheet(style);


Tx a lot,

zgulser
19th March 2010, 14:19
QPushButton::indicator
{
width: 20px;
height: 20px;
}

AL
19th March 2010, 14:22
this will set the button width and height to 20 px ... I would like to have the same width and height of the btn-orange-normal.png

zgulser
19th March 2010, 14:33
Oh sorry..So you wish to strecth your .png file to fit the button background?

What about adding "background-position: top-left;"?