简体   繁体   English

从插件中读取当前的 Qt Creator 主题

[英]Reading current Qt Creator theme from a plugin

There is a plugin for Qt Creator whose UI is just an ActiveX. Qt Creator 有一个插件,它的 UI 只是一个 ActiveX。

The problem is if a user changes the Qt Creator theme, the ActiveX doesn't reflect it.问题是如果用户更改 Qt Creator 主题,ActiveX 不会反映它。

That is why I need to pass information about colors to the ActiveX, but for that, the plugin has to read theme colors information.这就是为什么我需要将有关 colors 的信息传递给 ActiveX,但为此,插件必须阅读主题 colors 信息。 Also, the plugin needs to be notified when a current theme has just changed.此外,当当前主题刚刚更改时,需要通知插件。

I am absolutely a newbie in Qt.我绝对是 Qt 的新手。 Suddenly, I have not found an API to read theme colors.突然,我没有找到一个API来阅读主题colors。

Is there a way to get current theme colors from a Qt Creator plugin, and how to catch when the theme just changed?有没有办法从 ZE8801102A40AD89DDCFDCAEBF008D25Z Creator 插件中获取当前主题 colors,以及如何在主题刚刚更改时捕捉到?

There is src/libs/utils/theme/theme.h which contains the Utils::Theme class and function Utils::Theme *Utils::creatorTheme() .src/libs/utils/theme/theme.h包含Utils::Theme class 和 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.让插件依赖于 Utils 库(使用 qmake 添加QTC_LIB_DEPENDS += utils ,使用 CMake 将Utils添加到DEPENDS )并在要访问主题的源中包含#include <utils/theme/theme.h>

Get the theme with Utils::creatorTheme() .使用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 ).请注意,这是在核心插件的initialize方法中设置的,因此它在插件的构造函数中不可用,而只能在initialize和以后的方法中使用(请参阅插件生命周期)。

You can then query the Theme for the Theme::palette() and the various other task-specific colors.然后,您可以查询Theme Theme::palette()和其他各种特定于任务的 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.主题在运行时无法更改,因此您只需在启动期间(或稍后您需要设置您的东西)查询此主题是安全的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM