You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to get Dark Mode to work in Qt apps in AppImages? #155
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.
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
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-462374883case"${XDG_CURRENT_DESKTOP}"in*GNOME*|*gnome*|*XFCE*)
export QT_QPA_PLATFORMTHEME=gtk2
;;
esac
@srilakshmikanthanp does removing the hook altogether fix the problem, too? I'd consider removing it entirely (or at least not overwrite an existing value).
@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.
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.
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
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.
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.
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.
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).
@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.
Activity
srilakshmikanthanp commentedon May 26, 2025
I am also facing the same issue have you managed to fix this?
tpimh commentedon May 27, 2025
Nope, I believe this is just a limitation at the moment. I am not aware of anyone working on this.
srilakshmikanthanp commentedon May 27, 2025
I have used --custom-apprun script to set environment variable
QT_QPA_PLATFORMTHEME=xdgdesktopportalafter that theme detection works, In my case it seems to be set asgtk2in default apprun's hook so theme detection not workedTheAssassin commentedon May 29, 2025
Someone will have to research what files need to be added exactly before this issue can be resolved.
srilakshmikanthanp commentedon Jun 1, 2025
For me, the issue was caused by this hook. I resolved it by adding a custom application run script to override the
QT_QPA_PLATFORMTHEMEenvironment variable, setting it toxdgdesktopportal. 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:
TheAssassin commentedon Jun 1, 2025
@srilakshmikanthanp does removing the hook altogether fix the problem, too? I'd consider removing it entirely (or at least not overwrite an existing value).
srilakshmikanthanp commentedon Jun 8, 2025
@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.
TheAssassin commentedon Jun 8, 2025
Define users. End users of your application? Users of linuxdeploy who build app bundles?
srilakshmikanthanp commentedon Jun 8, 2025
Users of linuxdeploy who build app bundles.
TheAssassin commentedon Jun 8, 2025
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
xdgdesktopportalis universally OK, especially on older, still-supported distros. That would have to be tested.I am open to parameterizing this, though.
srilakshmikanthanp commentedon Jun 9, 2025
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.
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
scrubbbbs commentedon Nov 4, 2025
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.TheAssassin commentedon Nov 7, 2025
I suppose we should get rid of the hook script for Qt 6 then at least. I'll try to add a switch later.
TheAssassin commentedon Nov 7, 2025
The latest version no longer creates that hook file. Please test and report.
Skip AppRun hook creation on Qt >= 6
dougmassay commentedon Dec 1, 2025
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.
bjorn commentedon Dec 1, 2025
Just wondering, but was that really necessary? Explicitly requesting the
gtk3platform theme was causing issues with adjusting to dark mode (which are fixed by usingxdgdesktopportalinstead). 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.dougmassay commentedon Dec 1, 2025
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).
bjorn commentedon Dec 1, 2025
@dougmassay I guess the related comments may be outdated because it looks like the
gtk3platform 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_PLATFORMTHEMEunnecessarily. It will for sure mess with users trying to set it to something else for whatever reason.