Reading current Qt Creator theme from a plugin

187 Views Asked by At

There is a plugin for Qt Creator whose UI is just an ActiveX.

The problem is if a user changes the Qt Creator theme, the ActiveX doesn't reflect it.

That is why I need to pass information about colors to the ActiveX, but for that, the plugin has to read theme colors information. Also, the plugin needs to be notified when a current theme has just changed.

I am absolutely a newbie in Qt. Suddenly, I have not found an API to read theme colors.

Is there a way to get current theme colors from a Qt Creator plugin, and how to catch when the theme just changed?

1

There are 1 best solutions below

0
On BEST ANSWER

There is src/libs/utils/theme/theme.h which contains the Utils::Theme class and function Utils::Theme *Utils::creatorTheme().

Let the plugin depend on the Utils library (with qmake add QTC_LIB_DEPENDS += utils, with CMake add Utils to DEPENDS) and include with #include <utils/theme/theme.h> in the source where you want to access the theme.

Get the theme with Utils::creatorTheme(). Note that this is set up in Core plugin's initialize method, so it is not available in your Plugin's constructor, but only in initialize and later (see Plugin Life Cycle).

You can then query the Theme for the Theme::palette() and the various other task-specific colors.

The theme can not change during runtime, so you are safe with just querying this during startup (or at a later time where you need to set your things up.