Theme c++ interface

Is there some way to access the different variables in the Theme e.g.
Theme.fontSizeMedium in the C++ implementation ?

Not versed at all in Qt, but in general you would do something like this:

but Theme is a singleton, and it seems that won’t work.

A workaround:

1 Like

Yes the first approach I tried but that only resulted in 0

I Did something similar to the workaround .
I declared a property with a binding to Theme

ApplicationWindow {
property int nFontSizePx: Theme.fontSizeTiny

And then I could do something like
g_nFontSizePx = pU->rootObject()->property(“nFontSizePx”).toInt();

But all this seamed a bit awkward .

I did not try, and it won’t be compatible with Harbour rules (I guess). But, there is a package called sailfishsilica-qt5-devel (having a BuildRequires: pkgconfig(sailfishsilica) should pull it). This package contains a header file /usr/include/libsailfishsilica/silicatheme.h that is exposing the singleton with Silica::Theme::instance() (there is even a comment mentioning that it’s for C++ usage !). This singleton has signals when values change and getters for the font size and many other parameters.

3 Likes

This looks like what im looking for !

Thanks

Indeed what Damien said except that the library is even allowed harbour. We’ve been lacking documentation for the c++ side but I’ll try to make some improvements on that area. In the meanwhile just check the headers.

2 Likes

ohh I did not know that BuildRequires in the spec files downloads things for you .

Now it looks nicer

auto pTheme = Silica::Theme::instance();
g_nFontSizePx = pTheme->fontSizeTiny();

I made the following in the .pro file


INCLUDEPATH += $$[QT_HOST_PREFIX]/include/libsailfishsilica
LIBS += -lsailfishsilica

Or should that be done in some other way ??

You can also use a bit of PkgConfig magic in the pro file:

CONFIG += link_pkgconfig
PKGCONFIG += sailfishsilica

It will add the include path and the library as described in the pkg-config file for you (and take care of dependencies…).