Qt Stylesheets

I’m a new convert to Qt’s stylesheets. They make customizing your Qt GUI much easier than other methods (like QPalette). Recently, I responded to a request for comments from Trolltech, and I thought my fellow GUI developers might be interested in it.

These are my humble suggestions to Trolltech for improving Qt stylesheets:

I use stylesheets extensively for both tweaking and completely changing the look of a widget. By far, the most common thing I do with stylesheets is set the border of QFrames. They make it so easy to do this, for example:

border: none;
border-bottom: 1px solid black;

I also use them a lot for QFrame background colors. I find it much easier than messing with QPalette, especially when it comes to alpha transparency, background images, and gradient backgrounds.

My number 1 request: Let us reference an external CSS file in our stylesheet. In my current project, I had to patch designer so I could apply the same stylesheet to all my UI files, and actually see that style in Designer while working with it. If I could refer to an external file, I would make each Designer form point to a single stylesheet file (foo.css or :/foo.css), such that I could use a global stylesheet for all forms in my project and actually see how it will look in Designer before building and running my program.

My number 2 request (much less important): Make it easier to change single elements of a stylesheet programmatically. I often have the case where, for example, I want to change a blue gradient background to a gray one (say, when my widget is disabled). My stylesheet also has dozens of other settings that I don’t want to change (like border color, fonts, etc). It would be nice if I could access elements of the stylesheets like a DOM tree, and modify them in place without having to do search and replace on a QString. Currently the way I do it is with CSS comments. I place a START and END comment and then do search and replace to modify styles programmatically. It’s a hack, and I would like more fine-grained control than that.

In short, stylesheets are absolutely fantastic. I love that you have taken a wildly successful web concept and merged it into the world’s best GUI toolkit. Thank you Trolls!

These words of mine come from:

Write a Reply or Comment

Your email address will not be published.