PDA

View Full Version : Load palette from qss file



ilariari
15th April 2015, 11:27
Good morning to everybody!

In the application I'm working on, I have to to show a temperature.
I'm not dealing with a widget: just a rounded rect which width is proportional to the temperature and a text inside reporting the temperature value.
The rect's background color shall be related to the temperature: i wants to define a palette filled with gradually changing colors from the one associated to the lowest temperature to the one associated to the highest.

My customer wants to edit the palette content and use it without recompiling in order to define at release time the best color pattern in relation to the final application (ipse dixit!).

1) Is there in the Qt world something to manage a palette in a look-up table meaning (QPalette seems to me related to widget-specifics colors...) ?

My current purpose is to put the color values (say 255) in a qss file which is editable from the customer and loadable from the application in a smart way, so I ask:

2) How to load those 255 color values from qss file in a non trivial way (= without having to define 255 different QPROPERTYes and related READ functions) ?

Thank you very much for the time you'll spend in giving me some hint!

anda_skoa
15th April 2015, 12:42
Sounds to me as if the simplest solution would be to just read a list of strings from a text file.
E.g. using QSetting with IniFormat. or a trivial text format with one color per line.

Cheers,
_

d_stranz
15th April 2015, 16:59
You might also look at Qwt's QwtColorMap. This has several different versions that allow you to specify as few as two colors (start and end) that map to a real-world value range (0 - 100C, for example). You can also set color stops if you want to break the range into several sub-ranges, each with its own gradient. It is nearly a stand-alone class that can be used without the rest of the Qwt library (which by the way also has a "thermometer" widget in it).

ilariari
17th April 2015, 13:41
That's really a grat hint! I already installed Qwt in order to use QwtPlot; so it's not a problem to try it!
Thank you!