[Qt-interest] QStyle vs. style sheets

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Thu Jul 9 09:24:31 CEST 2009


Ben Axelrod wrote on Thursday, July 09, 2009 4:14 AM:

> I am using Qt to try to match the look and feel of an existing
> application.  The buttons in the app are very unique looking, and I
> have images for the various button states.  I am wondering if doing
> it through QStyle or style sheets would be better.  

I have never done "GUI pimping" myself, but from what I've read in the Qt docs (and heard at one of the Qt DevDays :) I think using Style Sheets (CSS) is good for "simple cases", e.g. changing the background pixmap of widgets, providing button state images etc.), but if you have lot of these widgets, it might not be as performant as using QStyleSheet.

Think of CSS as "being parsed at runtime" (maybe over and over again for each dialog popping up) and QStyleSheet as being "natively compiled" (after all, it is C++ code you are writing there).

QStyleSheets over you much more flexibility, but are somewhat more complicated to understand and more work is to be done, I guess.

As I said, I have used neither technique, but I would go for the CSS approach first. If it overs you the funtionality you need and you don't notice any performance loss in the GUI, then go for it. Otherwise implement your button states using QStyleSheets (I think for merely customising buttons QStyleSheets are not that hard, either - and I am sure there are examples in your QTDIR/exampels folder somewhere ;)


Cheers, Oliver
-- 
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22



More information about the Qt-interest-old mailing list