PDA

View Full Version : stylesheet help nedded



aj2903
14th February 2009, 11:23
I have declared new button and assgin stylesheet to it.


button = new QPushButton(this);
button->setText("TEST");
button->setGeometry(400,50,70,40);
button->setStyleSheet(
"color:white;\n"
"background:rgb(255,255,0);"
"border-radius:10px;\n"
"font:bold 16px;\n"
"font-family:\"Arial\";\n"
);


my the problem is: how to apply the below code

QPushButton:Pressed {
padding-left: 5px;
padding-top: 5px;
}

Lykurg
14th February 2009, 11:37
Hi, use normal CSS selectors:

button->setStyleSheet(
"QPushButton {color:white; background:rgb(255,255,0); border-radius:10px; font:bold 16px; font-family:\"Arial\";}"
"QPushButton:Pressed {padding-left: 5px; padding-top: 5px;}"
);

talk2amulya
14th February 2009, 11:48
there is also another way to do this.. use an external file and put all stylesheet code there..then load that file for loading the stylesheet of WHOLE application all at once..that way ur stylesheet code for pushbutton and other widgets wont be scattered around the whole project..and u wont have to make any changes in the code itself when u want a change to the look of the UI..all u'll have to do is change that external file..u can do it like this:


QString strCurTheme = "styles.qss";
QFile file(strCurTheme );
file.open(QFile::ReadOnly);
application.setStyleSheet(file.readAll());