PDA

View Full Version : How could QT apply style from an external CSS file?



bedbuffer
15th December 2010, 08:57
Hi All,

I would like the users to be able to customize the default look of our applications by simply loading their own CSS files. How do we accomplish that? Can anybody give me a jumpstart?

wysota
15th December 2010, 09:32
There is a -stylesheet commandline parameter QApplication supports. You can also just load the file directly in your app and apply its contents as the stylesheet of the application object.

bedbuffer
15th December 2010, 10:37
So if were the user, all I have to do is create a QT Stylesheet, place it in a folder and run the application with the -stylesheet parameter?

wysota
15th December 2010, 10:49
You can place it anywhere you want as long as you tell the application where the file is. Just check the source code first, I'm not sure the switch is actually called -stylesheet.

bedbuffer
16th December 2010, 10:15
The styles for the controls work but not when I'm trying to load a background image for the MainWindow. I tried:

QMainWindow{
background-image:url(image_256_8bit_latest_back.png);
}

Can you tell me what's wrong with this StyleSheet?

wysota
16th December 2010, 11:41
You are using a relative path.