[Interest] working with external stylesheet in Qt Designer

Alejandro Exojo aexojo at modpow.es
Mon Apr 8 10:15:40 CEST 2013

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

Yes. :)

> 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)

That would be the ideal solution: point the widget's stylesheet to a
file, instead of the text, but...

> 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/pyqt@riverbankcomputing.com/msg16133.html ).
> 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

More information about the Interest mailing list