Discussion:
[Interest] working with external stylesheet in Qt Designer
Hamish Moffatt
2013-04-05 00:55:47 UTC
Permalink
Hi,

tl;dr: is there any way to edit/preview forms in Qt Designer with
stylesheet loaded from an external file?


My application has various custom forms and widgets I've designed in Qt
Designer which depend extensively on stylesheets. For preview purposes
I've put stylesheets into each form, but I have different styles
depending on screen size and which skin is selected, so I need to load
the style into qApplication once, but still be able to preview it in
Designer.

This looks like a common question from my googling; is there a solution?
Here are some ideas which don't help;

1. Qt Stylesheets don't support CSS's @include (QTBUG-2047 proposes it)

2. In Designer's settings you can set up a preview with a stylesheet,
but you have to specify the text (can't refer to a file)

3. A poster to the PyQT list hinted at creating a designer extension
which automatically loaded the stylesheet from an external file but I
haven't found any details. (
http://www.mail-archive.com/***@riverbankcomputing.com/msg16133.html ).
How could this work?



thanks

Hamish
Alejandro Exojo
2013-04-08 08:15:40 UTC
Permalink
Post by Hamish Moffatt
tl;dr: is there any way to edit/preview forms in Qt Designer with
stylesheet loaded from an external file?
Yes. :)
Post by Hamish Moffatt
2. In Designer's settings you can set up a preview with a stylesheet,
but you have to specify the text (can't refer to a file)
That would be the ideal solution: point the widget's stylesheet to a
file, instead of the text, but...
Post by Hamish Moffatt
3. A poster to the PyQT list hinted at creating a designer extension
which automatically loaded the stylesheet from an external file but I
haven't found any details. (
How could this work?
Since my custom widgets were a subclass anyway, I created a Designer
extension to such subclasses. Is very easy, and you just have to write
some boilerplate. If you are not already doing it, you can load the
stylesheets through QResources, so the Designer extension has the
styles built in. If you are not doing it and you don't want/can't do
it, you can add some #ifdef that check if QDESIGNER_EXPORT_WIDGETS is
defined, and use QResources only there.

Let us know if you need more info.
--
Alejandro Exojo Piqueras

ModpoW, S.L.
Technova LaSalle | Sant Joan de la Salle 42 | 08022 Barcelona | www.modpow.es
Loading...