Skip to content

How to get Dark Mode to work in Qt apps in AppImages? #155

Open

Description

@tpimh

I am trying to package a Qt application in an AppImage. The app always has the default look regardless of the OS setting to use Dark Mode.

I tried to solve this problem by manually adding libqt5ct.so and libqt5ct-style.so to the AppImage, but this didn't change anything. My qt5ct outside of AppImage is set to use "Fusion" style with "darker" color scheme, but I still get the default look when launching the AppImage.

Activity

  1. srilakshmikanthanp commented on May 26, 2025

    @srilakshmikanthanp

    I am also facing the same issue have you managed to fix this?

  2. tpimh commented on May 27, 2025

    @tpimh
    Author

    Nope, I believe this is just a limitation at the moment. I am not aware of anyone working on this.

  3. srilakshmikanthanp commented on May 27, 2025

    @srilakshmikanthanp

    I have used --custom-apprun script to set environment variable QT_QPA_PLATFORMTHEME=xdgdesktopportal after that theme detection works, In my case it seems to be set as gtk2 in default apprun's hook so theme detection not worked

  4. TheAssassin commented on May 29, 2025

    @TheAssassin
    Member

    Someone will have to research what files need to be added exactly before this issue can be resolved.

  5. srilakshmikanthanp commented on Jun 1, 2025

    @srilakshmikanthanp

    For me, the issue was caused by this hook. I resolved it by adding a custom application run script to override the QT_QPA_PLATFORMTHEME environment variable, setting it to xdgdesktopportal. This made the application to detect theme properly on Ubuntu 24.

    Does it make sense to have a custom hook to handle this on the user's end?

    Here's the original snippet:

    # generated by linuxdeploy-plugin-qt
    
    # try to make Qt apps more "native looking" on Gtk-based desktops, if possible
    # see https://github.com/AppImage/AppImageKit/issues/977#issue-462374883
    case "${XDG_CURRENT_DESKTOP}" in
        *GNOME*|*gnome*|*XFCE*)
            export QT_QPA_PLATFORMTHEME=gtk2
            ;;
    esac
    
  6. TheAssassin commented on Jun 1, 2025

    @TheAssassin
    Member

    @srilakshmikanthanp does removing the hook altogether fix the problem, too? I'd consider removing it entirely (or at least not overwrite an existing value).

  7. srilakshmikanthanp commented on Jun 8, 2025

    @srilakshmikanthanp

    @TheAssassin In my case, theme detection only works if I set export QT_QPA_PLATFORMTHEME=xdgdesktopportal. I verified this by unsetting it (export QT_QPA_PLATFORMTHEME=""), and theme detection stopped working.

    Would it be acceptable to allow users to optionally provide a hook file so they can configure this on their end if needed, with an empty hook or current behavior as the default.

  8. TheAssassin commented on Jun 8, 2025

    @TheAssassin
    Member

    Define users. End users of your application? Users of linuxdeploy who build app bundles?

  9. srilakshmikanthanp commented on Jun 8, 2025

    @srilakshmikanthanp

    Users of linuxdeploy who build app bundles.

  10. TheAssassin commented on Jun 8, 2025

    @TheAssassin
    Member

    As I said I am open to removing the hook altogether, I am not sure if it is still helpful at all. Plus, I already suggested that we can just accept a predefined value.

    I am not sure that setting xdgdesktopportal is universally OK, especially on older, still-supported distros. That would have to be tested.

    I am open to parameterizing this, though.

  11. srilakshmikanthanp commented on Jun 9, 2025

    @srilakshmikanthanp

    If the default app run script only launches the application without any additional setup, users can simply replace it with a custom script to handle all required tasks, such as setting the QT_QPA_PLATFORMTHEME environment variable. In that case, removing the hook altogether would be fine. However, if the default script performs more than just starting the app, offering a way to inject a custom hook script would be valuable. It would let users run additional steps before executing app without needing to override the entire default run.

    In my case, I’ve overridden the default app run script to set the QT_QPA_PLATFORMTHEME environment variable and then simply launched the application. So, removing the hook mechanism would be fine for my case.

    I am not sure that setting xdgdesktopportal is universally OK, especially on older, still-supported distros. That would have to be tested.

    Yes we should not set any value to that, it would be better to set by user based on their requirements. Also we can put this note in some docs so if some one has same problem they can fix it without spending much time

  12. scrubbbbs commented on Nov 4, 2025

    @scrubbbbs

    I also agree it would be better if this was not set at all, and let it be up to users running the AppImage. I used to use qt6ct on my desktop (which requires QT_QPA_PLATFORMTHEME=qt6ct) , and this hook would break that.

    Also the gtk2 platform theme (libqtgtk2.so) is not typically installed in Qt6, and there is no apt package for it.

  13. TheAssassin commented on Nov 7, 2025

    @TheAssassin
    Member

    I suppose we should get rid of the hook script for Qt 6 then at least. I'll try to add a switch later.

  14. TheAssassin commented on Nov 7, 2025

    @TheAssassin
    Member

    The latest version no longer creates that hook file. Please test and report.

  15. added a commit that references this issue on Dec 1, 2025
  16. dougmassay commented on Dec 1, 2025

    @dougmassay

    The default QT_QPA_PLATFORMTHEME=gtk3 was working in most of my use cases. My issue was that I was using a custom AppRun that was still adding the call to source the hook. So when the hook creation was removed 3 weeks ago, my Qt6 AppImage broke (when building with the latest linux-deploy-qt plugin). I tracked it down and just incorporated the contents of the hook script into my custom AppRun, but I was sure confused as to what had happened for a while. There was no link to this issue in the commit that removed the hook creation.

  17. bjorn commented on Dec 1, 2025

    @bjorn
    Contributor

    I tracked it down and just incorporated the contents of the hook script into my custom AppRun

    Just wondering, but was that really necessary? Explicitly requesting the gtk3 platform theme was causing issues with adjusting to dark mode (which are fixed by using xdgdesktopportal instead). Hence it was judged better to leave this variable alone and make it easier for the user to customize the platform theme when they need to.

  18. dougmassay commented on Dec 1, 2025

    @dougmassay

    I'm very much in "if it ain't broke, don't fix it mode" here. I'm not experiencing issues with changing themes (dark or light) on the fly on the DEs I've tested with when using the default hook that sets the QT_QPA_PLATFORMTHEME to gtk3 (on the DEs specified in the hook). My minimum is Ubuntu 22.04 so I don't typically have to worry about older DEs that might use gtk2. If I get any user reports of theme breakage, I'll of corse revisit. But for now, I'm satisfied with what the plugin's hook script was providing by default (prior to 3 weeks ago).

  19. bjorn commented on Dec 1, 2025

    @bjorn
    Contributor

    @dougmassay I guess the related comments may be outdated because it looks like the gtk3 platform theme learned to respect light and dark theme preference since Qt 6.8 (see qt/qtbase@d0b4e8a).

    You may anyway want to try whether you can just remove it, because by the same "if it ain't broke, don't fix it mode" logic, you don't want to be setting the QT_QPA_PLATFORMTHEME unnecessarily. It will for sure mess with users trying to set it to something else for whatever reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions