PDA

View Full Version : Setting font throught setStylesheet command



qtnewbi3
21st October 2011, 20:41
Hi,

I have already used the designer to give a pushbutton the following stylesheet and tested that it works.


QPushButton {
border-image: url(:/Images/a.png);
font: 75 13pt "Droid Serif [unknown]";
color:black;
}

QPushButton:pressed {
border-image: url(:/Images/b.png);
color: darkred;
}

I was trying to make sure that if a button is clicked it stays the in the pressed state in terms of color and background image and font so as to give the illusion that it is selected.
To do this i used the following command in my style sheet.


button->setStylesheet(setStyleSheet(QString::fromUtf8("border-image: url(:/Images/b.png);color: darkred;font: 75 13pt;"));
I dont know where to put the font name ie "Droid Serif [unknown]" as the quotation marks confuse the program if i do it in the same manner as the designer. I have tried appending it as a separate string but it doesnt work. Could anyone give me an example of using the setstylesheet with similar parameters and also setting the font.

Thanks

Spitfire
24th October 2011, 10:26
Escape the quotes ie:
pushButton->setStyleSheet(QString::fromUtf8("font: 75 italic 8pt \"MS Sans Serif\";"));

qtnewbi3
24th October 2011, 14:39
thank you so much.... noob mistake... i was thinking i had to use the setFont command or something else.... my CSS is horrible...

Spitfire
25th October 2011, 09:58
I'm glad I could help :)