Style Sheets vs QStyle



  • Hi
    I am looking into the possibilities offered by Qt to provide my applications with a custom style.
    There appears to be a choice of using style sheets or to implement the the style by deriving from QProxyStyle.
    What are the advantages of using one method over the other?
    Which is more efficient?
    Which is easier to implement and maintain
    Which is more flexible

    If anyone has any advice on which way I should go I would be grateful to hear from you

    Thanks


  • Moderators

    Writing own styles (QStyle inheritance) is harder to implement, but faster and more flexible.
    Using QSS (Qt Style Sheets) is easier to do, but the performance is slower (especially startup, when the QSS file needs to be parsed. Later, the difference is hardly noticeable). I think QSS is also a bit easier to maintain.

    So, neither is the perfect solution. If you plan just simple, cosmetic changes to the look & feel, I recommend using QSS, it's much easier for small tasks. If you aim for a total departure from platform style, go for QStyle. QSS has a nasty habit of quickly becoming unreadable, hard to debug and the longer the file, the longer it takes to parse it.



  • Hi,

    first I share with you few screenshots done with QSS on top the common qt style (default implementation) because rarely you'll find some examples giving you an idea of how much you could push with QSS in qt:

    "screenshot 1":http://s813.photobucket.com/user/PopescuNicu/media/helix_main_media_zps7ebbda16.png.html?sort=3&o=0
    "screenshot2":http://i813.photobucket.com/albums/zz55/PopescuNicu/helix_infobar_zpsc4398dd2.png

    bq. Style sheets are applied on top of the current widget style, meaning that your applications will look as native as possible, but any style sheet constraints will be taken into consideration.

    bq. Style sheets let you perform all kinds of customizations that are difficult or impossible to perform using QPalette alone. If you want yellow backgrounds for mandatory fields, red text for potentially destructive push buttons, or fancy check boxes, style sheets are the answer.

    bq. Warning: Qt style sheets are currently not supported for custom QStyle subclasses. We plan to address this in some future release.

    keeping these in mind, at least:

    on speediness: I think is improper to compare them since QSS is an additional mechanism, at some points interleaved with qt style; so without any style sheet just widget's style is processed, while one is present the style and style sheet are processed in tandem; I think loading a qss file is not a problem, but the style sheet(a long QString) parsing at run time is expensive

    on flexibility: I don't know in what way QStyle is flexible, maybe as API

    bq. There's also the risk that the caller might pass the wrong widget type. Still,this was an acceptable price to pay for the flexibility provided by enums.

    this is from a former qt's review but is not relevant enough imho... I think better to ask the Q: how much to change(if possible) to get a customized graphical element? for instance how it would be QSS's padding done by QStyle only?

    with its boxing model QSS has features hardly achievable by QStyle only

    btw, the screenshots are from an ARM system with a 600 MHz!!! CPU and GPU with opengl es2 ... I use QGrahicsView with a gl viewport, qss on any single widget, and things happen fast



  • Hi Nicu
    Thanks for your reply.
    Do you know of any example of advanced style sheets like the example screen shots ?



  • Hi,

    in general, you don't need other qss examples than qt's doc one:

    "Qt Style Sheets Reference":http://qt-project.org/doc/qt-5.0/qtwidgets/stylesheet-reference.html and the afferent customizing examples ... and CSS specifications you could find online

    but what you'd need to understand is that beside QSS mechanism, in order to achieve some effects the app's design must provide additional widgets handling, like specific stack order on different events etc.

    in rest, most is photoshop art work :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.