[Interest] Qt Styles
bthorsen at ics.com
Mon Jun 10 08:00:01 CEST 2013
Den 10-06-2013 03:58, Andres L. skrev:
> I need a new style for an application I'm going to develop. I've looked
> for it and I found three ways to make it:
> 1) Subclass QStyle and reimplement virtual functions (the static way)
> 2) Use QProxyStyle
> 3) Use Qt Style Sheets
> I've particularly interested with the first one, but I actually don't
> know exactly when to choose one of them. Moreover, I have not found any
> example (easy to understand, at least) of the (1) and (2) options.
There is an example in the Qt sources called Norwegian Wood (I think).
It should tell you what you need.
> In the link there is an image with the style I need. For instance, in
> the image I have a "circular" progress bar, I can't find how to make it.
In the style subclass, you have to implement a bunch of functions, and
we can take this one as an example.
For a widget like progress bar, this is what happens in it's painter:
1) Create a style option object
2) Ask the style for the boxes where things should be painted
3) Ask the style to paint the parts of the widget
This means you have to implement the part of the method where
QProgresBar gets the QRect for the bar, the progress and the text. You
might have to be creative to get the round bar area. And you also have
to implement the painting methods in the style.
All methods (almost) in the styles are of this type:
case progress: do stuff
> Also, I need to know which of those 3 alternatives is the "lightest", I
> mean, which consumes the minimum resources (less RAM?, less CPU?, etc.).
If you are worried about this, forget all about style sheets. They are
heavy and slow. But on the desktop they are usually fast enough.
If you really have a complete style, it's a better idea to implement a
Bo Thorsen, European Qt Manager, Integrated Computer Solutions
ICS - Delivering World-Class Applications for Embedded & Mobile Devices
More information about the Interest