Skip to content

Conversation

benthecarman
Copy link
Contributor

Enable GTK3 platform theme integration on Linux to properly detect
system dark/light mode settings. Without this, Qt applications on
Linux don't automatically adapt to the system theme, unlike macOS
where it works out of the box.

The fix sets QT_QPA_PLATFORMTHEME to "gtk3" before QApplication
initialization, but only if the user hasn't already set a platform
theme. This respects existing user configurations while providing
better defaults for desktop environments using GTK (GNOME, Unity,
XFCE, MATE).

The change is non-breaking as Qt falls back gracefully if the GTK
platform theme plugin is unavailable

  Enable GTK3 platform theme integration on Linux to properly detect
  system dark/light mode settings. Without this, Qt applications on
  Linux don't automatically adapt to the system theme, unlike macOS
  where it works out of the box.

  The fix sets QT_QPA_PLATFORMTHEME to "gtk3" before QApplication
  initialization, but only if the user hasn't already set a platform
  theme. This respects existing user configurations while providing
  better defaults for desktop environments using GTK (GNOME, Unity,
  XFCE, MATE).

  The change is non-breaking as Qt falls back gracefully if the GTK
  platform theme plugin is unavailable
@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 23, 2025

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.
A summary of reviews will appear here.

@hebasto
Copy link
Member

hebasto commented Sep 23, 2025

Enable GTK3 platform theme integration on Linux to properly detect
system dark/light mode settings. Without this, Qt applications on
Linux don't automatically adapt to the system theme, unlike macOS
where it works out of the box.

Could you please clarify which build this change is intended to affect, statically linked or shared?

If the latter, which system was this tested on (OS, desktop environment, Qt version)?

@hebasto hebasto changed the title qt: Fix dark mode detection on Linux Fix dark mode detection on Linux Sep 23, 2025
@hebasto hebasto added the Linux label Sep 23, 2025
@luke-jr
Copy link
Member

luke-jr commented Sep 23, 2025

Seems like this could make things worse for native (Qt) environments?

@benthecarman
Copy link
Contributor Author

Could you please clarify which build this change is intended to affect, statically linked or shared?

If the latter, which system was this tested on (OS, desktop environment, Qt version)?

this sadly only effects dynamically linked builds.

I have tested on ubuntu 24.04 with Qt 6.4.2

@hebasto
Copy link
Member

hebasto commented Sep 23, 2025

Could you please clarify which build this change is intended to affect, statically linked or shared?
If the latter, which system was this tested on (OS, desktop environment, Qt version)?

this sadly only effects dynamically linked builds.

Bringing this functionality to statically linked (including release) binaries would require introducing new build dependencies. There is a consensus among Core developers that this should only be considered after separating the GUI build into its own Guix script.

I have tested on ubuntu 24.04 with Qt 6.4.2

On the same system, the master branch @ 34fefb6:

image

Everything seems to be working correctly.

@katesalazar
Copy link
Contributor

Ah, nice and small, thanks. I have a couple of questions.

This is in your code:

This must be done before creating the QApplication

Does this mean window won't change live when theme changes, on Linux?

This is in your post:

unlike macOS where it works out of the box.

Does this mean window will change live when theme changes, on macOS?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants