How to get correctly Kirigami theme colors?

Hello! I just signed up to KDE Discuss, I hope this is the right place to post this. This is probably a stupid question but I’m struggling to make this work. In my C++ class I’m trying to get Kirigami::PlatformTheme::linkColor, so I tried this:

#include <Kirigami/PlatformTheme>
...
Kirigami::PlatformTheme* theme = new Kirigami::PlatformTheme;
qWarning() << "color: " <<theme->linkColor();

but I’m getting color: QColor(Invalid). What am I doing wrong?

I have always worked with QML only and just a bit of C++, but now I’m trying to implement a custom QSyntaxHighlighter and need to access system colors.

thanks in advance!

Hi try something like this:

Kirigami::PlatformTheme* theme = static_cast<Kirigami::PlatformTheme *>(qmlAttachedPropertiesObject<Kirigami::PlatformTheme>(this, true));

3 Likes

yes this works! thank you very much!!! Basically you’re using the QML object casting it as a Kirigami::PlatformTheme, am I correct? and defining the object just as new Kirigami::PlatformTheme didn’t work because it’s like the new object is “empty”?

thank you very very much!

1 Like

Yeah exactly it’s just reusing the object which was exposed to the qml engine. When creating a new object it’s otherwise empty.

1 Like