I’ve been spending a couple of days on an investigation about how to integrate Qt apps better in GTK based environments. So far I had partial success and maybe this thread could help someone else or be a starting point for the further discussion and investigation on achieving the best possible theme integration available at this time, and in the future with snapcraft improvements…
- Ugly mouse cursor (fallback theme) can be fixed on some DEs
- GTK theme integration can be achieved on some systems via the QGtkStyle (gtk2) plugin (with drawbacks though)
- Not all distros/DEs expose the right gtk2 settings file and/or provide appropriate GTK2 theme versions
- QGnomePlatform is a very promising project to solve this for GTK3 themes, looks like the proper way to go, but at this time it appears to be not working on Ubuntu, upstream issue filled here.
How to Fix Ugly Fallback Mouse Cursor Theme for Qt Apps
EDIT: there’s now a better way to do this, see next posts below…
The snap needs the correct plugs to access the icon theme and a specific package needs to be staged additionally.
plugs: # additional plug to fix mouse cursor theme
and stage package:
- qt5-style-plugins # for mouse cursor theme fix
For a complete example, please look at the following snapcraft.yaml
Issues: currently this works only on distros and DEs that also pick up the gtk2 theme, when not supported the fallback cursor is still used. Distros I tested that pick the GTK2 theme up are Ubuntu and elementaryOS for example, no success on Manjaro, Mint, Kubuntu. I think it is safe to integrate this feature since it has no drawbacks and only advantages when supported.
How to Integrate a Qt App with the System’s GTK default Theme
Like above, this works only on a few distros and DEs that export GTK2 themes properly (similar to Ubuntu). The big drawback of this method is that if a distro/DE is not supported it will show an ugly GTK fallback theme instead of the default fusion style, see images below
Default fusion style (Qt apps right now):
QGTKStyle integration on Ubuntu 16.04, works also with Yaru, Adwaita, and more themes:
QGTKStyle on elementaryOS:
Fallback GTK theme when not working (Mint, Zorin, Kubuntu, Manjaro):
Add the following code to your snapcraft.yaml:
plugs: # additional plugs to pick up the GTK theme and icons from the system
QT_QPA_PLATFORMTHEME: gtk2 # set default theme to gtk to integrate with system theme (GTK2)
In the app section append the
-style gtk2 override to your command like this:
command: desktop-launch symphytum -style gtk2
This is required because somehow the
QT_QPA_PLATFORMTHEME env variable is not picked up, so we can force a specific Qt style with that switch. For a complete example, see this snapcraft.yaml file.
I think this is not safe to add unconditionally to your snap at this stage because it will fallback to the ugly GTK fallback theme on unsupported setups (quite a few). Maybe you could ship a different snap with enabled GTK integration for the users who wish to use it on supported systems like Ubuntu and elementaryOS. Some systems like Mint also support this when changing to a compatible theme which includes the GTK2 theme like Adwaita on Mint.
As an end user of such snap you can always force the default Qt fusion style by passing the override switch like
symphytum -style fusion this will launch the app with
fusion style, regardless of what the snap packager set.
I hope with this thread we can investigate this further maybe even fix the theming for currently unsupported systems. The best solution would be to get the QGnomePlatform plugin to work on a core18 base (work in progress snapcraft.yaml), I think that would also work on most systems because GTK3 is much more similarly configured across different distros.