Handling dark theme mode in Kirigami apps

Hello!

I am in the process of rewriting EasyEffects in Qt/QML/Kirigami and it is not clear to me how dark theme mode is supposed to be handled outside of KDE. Inside KDE the app follows what is done in systemsettings as expected. But this does not happen when it runs on GNOME. Does anyone know what should be done?

Best regards,
Wellington

4 Likes

Have you set KIconThemes + QT_QUICK_CONTROLS_STYLE?

Hi @Herzenschein ! I did

KLocalizedString::setApplicationDomain(APPLICATION_DOMAIN);
  QCoreApplication::setOrganizationName(QStringLiteral(ORGANIZATION_NAME));
  QCoreApplication::setOrganizationDomain(QStringLiteral(ORGANIZATION_DOMAIN));
  QCoreApplication::setApplicationName(QStringLiteral("EasyEffects"));
  QCoreApplication::setApplicationVersion(PROJECT_VERSION);

  if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
    QQuickStyle::setStyle(QStringLiteral("org.kde.desktop"));
  }

Oh… So I also need

KIconTheme::initTheme();

and

QApplication::setStyle(QStringLiteral(“breeze”));

?

Maybe. That was added recently in Use new KIconTheme init in Kirigami tutorial (!427) · Merge requests · Documentation / Developer Tutorial and Article Site · GitLab and originates from extend initTheme to ensure we properly follow the system colors (!143) · Merge requests · Frameworks / KIconThemes · GitLab

I’m not entirely sure whether the KIconTheme stuff automatically selects Breeze Dark in other environments that have a dark theme set.

I think the expert on this would be @Christoph_Cullmann

1 Like

I see. I will give it a try. But for now I am having some problems with the KiconTheme include header. I’ve changed my cmake files and “KF6IconThemes” is found. But somehow compilation fails because the header

#include <KIconTheme>

is not found. Strange…

And the target link to

KF6::IconThemes

somehow also fails with not found. I wonder if something is missing in the Arch Linux package. As far as I could see there is one “kiconthemes” package in the repository.

The issue with the link is fixed. I’ve typed the wrong thing. Now only the include header problem remains.

Somehow the include header issue was fixed now that the link was properly done. The question now is if what is done in the tutorial is enough for dark/light theme switching to just work when the app is used on GNOME or if some kind of manual control in the app settings will be necessary.

One of EasyEffects developers tested on her computer and the theme now switches to dark mode automatically on GNOME. Nice! Thanks for the help @Herzenschein ! :slight_smile:

2 Likes

Hello @Herzenschein ! Based on the reports done by the EasyEffects developer that uses GNOME it seems that a regression happened after kde frameworks was upgraded from 6.8.0 to 6.9.0. The switching to the dark theme is not happening on her GNOME installation anymore. Are you aware of any change on KDE’s side related to this? What would be the proper place for a bug report?

1 Like

I finally had some time to test in a laptop where I still have GNOME. The regressions seems to be the configuration being reset when GNOME does a logout. When setting the theme on GNOME settings things work as expected. But in the next GNOME login the configuration Kirigami is using to do its magic seems to be reset. And it uses the light theme when GNOME is using dark theme.

Actually there is no need to logout. Just closing the app and opening it again resets it to the light theme. We’ve opened a bug report 497790 – Dark mode/theme not working in Gnome.