How to set a native Qt theme in Qt 5.15.9 on GNOME?
-
This is related to a previous post I made here, but I've managed to narrow it down much more.
I have a Qt 5.15.9 application built for Red Hat Enterprise Linux 9 (using GNOME), which is having issues with the QGtk3Theme plugin (from qt5/plugins/platformthemes/libqgtk3.so). Just based on the name, it seems like this class should only be involved in Qt if a gtk style is being used, but I can't seem to bypass it.
I found this thread which highlights some issues with libqgtk in newer versions of Qt5:
https://forum.qt.io/topic/75398/qt-5-8-0-qapplication-invalid-style-override-passed-ignoring-it/7
And it suggests this solution:qputenv("QT_STYLE_OVERRIDE", "");
I tried this with the empty string, and also with "Windows" and "Fusion", which are the only two styles that print when I use:
qDebug() << QStyleFactory::keys();
None of that changed the segfault I get in QGtk3Theme::QGtk3Theme().
I've also found this page which seems to describe something similar, QGtkStyle:
https://wiki.archlinux.org/title/Uniform_look_for_Qt_and_GTK_applications#QGtkStyle
What it describes makes sense, some Qt themes (are those different from styles?) rely on gtk in the backend. It seems like QGtk3Theme is just the gtk3 version of QGtkStyle. It says you can enable this theme by setting the QT_QPA_PLATFORMTHEME environment variable to "gtk2", but I just want to disable it. I've tried setting that variable to "gnome", "qt5ct", or just "" in the source code before setting style override to Fusion or Windows, but still get the same segmentation fault.I think I generally understand what QGtk3Theme is, and I also expect it to break. This app was originally made in RHEL7 with qt4, and that version also broke when trying to use a gtk-based style like GTK+. It instead used the adwaita style, which looks like gtk but is still native Qt.
What I don't understand is why I can't seem to enable a native Qt style that doesn't depend on gtk in RHEL9. Is there some other way that gtk themes can be enforced that I'm missing?I even tried running the RHEL7/qt4 version of the app on RHEL9, and the same sort of thing happens. Even with the style set to adwaita, a native Qt style, the program segfaults in gtk libraries just like it does when adwaita is disabled on RHEL7.
Any help is appreciated, thanks.
-
I figured out a solution that did not require any new version of QT or messing with the libraries.
Setting the environment variable XDG_CURRENT_DESKTOP=kde did the trick. I have yet to test with the Qt4 version, but since it works for Qt5 and that was my original question I am marking this solved. -
Hi,
From past memory, I remember there has been some fixes for GTK3 at some point. You may have to build a more recent version of Qt 5 or maybe consider using Qt 6.
-
@SGaist Do you think it's possible for me to just not use the GTK3 stuff at all? I have no attachment to any style, and I don't think the original software was even designed to use it at all. It seems like it's just being forcibly enabled somehow in RHEL9.
Installing new software is kind of a big pain on this system, so I'd like to try everything I can before that.
-
One thing you can do is move the GTK platform theme library somewhere else.
-
I figured out a solution that did not require any new version of QT or messing with the libraries.
Setting the environment variable XDG_CURRENT_DESKTOP=kde did the trick. I have yet to test with the Qt4 version, but since it works for Qt5 and that was my original question I am marking this solved. -