[Qgis-developer] Font size problem

Larry Shaffer larrys at dakotacarto.com
Thu Jun 13 09:58:44 PDT 2013


Hi Josua,

On Thu, Jun 13, 2013 at 7:15 AM, Josua S <josh-talk at hotmail.com> wrote:

> Hello
>
> I am working on a QGIS Python plugin and I have a problem concerning font
> sizes. With QDialogs I have no problem to set the font sizes. But as soon
> as I work with a QDockWidget and add it to QGIS every font size settings
> are ignored. Qt Creator shows the correct font sizes but QGIS seems to
> overwrite these settings. Does this behaviour have a reason and is there a
> possibility to prevent QGIS from overwriting these font size settings?
> Thank you very much.
>

If you are developing your plugin for QGIS 2.0+, there is now an option to
set the font family and size used in the application under Options>>General
dialog. This font is set using Qt stylesheets [0]. I believe this was also
the case with QGIS 1.8, but the font was the default for the platform and
not easily changeable. There is currently no documentation about this in
the PyQGIS Cookbook, but basically you can try these two following
approaches:

* Any widget that is a child of the main application or one of its widgets
(e.g. iface or app's QMainWindow) will inherit the font set in Options. To
override, set a custom stylesheet for your widgets or their components. Try
to avoid wildcard assignment of styles, i.e. " * { color: #fff; } " OR "
color:#fff; ", as this will cause the widget to not use the host window
server's applied style and you will then have to style most aspects of the
widget starting with a Qt-style default.

Instead, use something like " QLabel { color: #fff; } " or one of the other
non-wildcard (aka non-universal) Qt stylesheet selectors [1]. You can set
the stylesheet in Qt Designer or in the .ui editor in Qt Creator.

When working with font sizes, opt to honor the user's chosen app font
setting, i.e. just like styling with CSS define the sizes using em or ex
units so they are relative to the app font [2]. This will ensure the sizing
works across most platforms and differing screen resolutions.

* Don't set the parent for your widget. This will most likely cause the
widget to *not* inherit the app's stylesheet. (This is probably why your
dialogs were not having their style overridden, if you didn't set a
parent.) However, it is generally best practice to assign a parent to a
widget, so I would avoid this approach and go with local stylesheet
overrides as noted above.

NOTE: stylesheets generally override any similarly set Qt widget style
properties.

[0] http://qt-project.org/doc/qt-4.7/stylesheet.html
[1] http://qt-project.org/doc/qt-4.7/stylesheet-syntax.html
[2]
http://qt-project.org/doc/qt-4.7/stylesheet-reference.html#id-55cf595e-a426-464c-9813-8cc49d142046

Regards,

Larry



> Josua
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20130613/f96f0fbf/attachment.html>


More information about the Qgis-developer mailing list