Unable to change color theme using C++
The only interface I found for setting the view theme in a C++ plugin is the ConfigInterface, but it doesn't seem to work.
The implementation I found is here } else if (key == QLatin1String("theme") && value.type() == QVariant::String) {
, but this line is never reached because this prior condition if (value.canConvert<QColor>()) {
is always true and the function exits before reaching the other line.
Test code used:
void setTheme(const QString &theme)
{
auto* app = KTextEditor::Editor::instance()->application();
for (auto* win : app->mainWindows()) {
for (auto* view : win->views()) {
auto* viewcfg = qobject_cast<KTextEditor::ConfigInterface*>(view);
if (viewcfg) {
viewcfg->setConfigValue("theme", theme);
}
}
}
}
Test for QVariant::canConvert:
#include <QVariant>
int main() {
QVariant v = "abcd";
printf("%d\n", v.canConvert(QVariant::Color)); // 1
}
Edited by Ibrahim Abdullah