PDA

View Full Version : How to execute my .css file in Qt?



harish
2nd December 2011, 10:31
Hi,
I am having a .css file(with some button images and background image) instead of using style sheet and had added it to my project.

I don't know how to link the .css file with my button image and background.

If anyone knows how to add it please get me some sample or examples for it.



Thanks in advance,
Harish.M

Oleg
2nd December 2011, 10:46
Add your style sheet file to resource (.qrc), and then load it from there.

harish
2nd December 2011, 11:26
Hi Oleg,

I added my style sheet file to .qrc and still now it is not executing.
What might be the error i had done help me to solve this..

FelixB
2nd December 2011, 11:32
just adding is not enough. you can add whatever you want ;)

you have to set the style. read the content of your css file into a QString. then set this QString as Style to your application.

Oleg
2nd December 2011, 11:39
Quick snippet:


QFile f(":/styles.qss");
if (f.open(QIODevice::ReadOnly)) {
qApp->setStyleSheet(QString(f.readAll()));
f.close();
}

harish
2nd December 2011, 12:12
Thank you everyone for your replies i will try it and let me see.

It works fine thank you everyone