PDA

View Full Version : Qt Application Not Using GTK Theme on Linux



Assoluto
8th November 2016, 20:58
When I run my Qt application on Linux Mint Cinnamon 18 it doesn't use the GTK theme colours or system font. Qt Creator has the same issue, but other Qt applications I've tried (XnView MP and qBittorrent) do correctly use my GTK theme. It therefore appears there is a way to get it to work, but I'm unsure how.

I tried this (even though it should be true by default):


QApplication::setDesktopSettingsAware(true);
That didn't work, so I tried forcing the style to Fusion with:


QApplication::setStyle(QStyleFactory::create("Fusion"));
This too had no effect. I asked on Stack Overflow and somebody said he solved the issue using:


qApp->setStyle(new QProxyStyle());
Unfortunately that didn't work for me. I've looked at the qBittorrent code to try and work how why that follows the GTK theme while my application doesn't, but I couldn't see anything relevant to the issue. I also tried making a very simple Qt application, but that too doesn't use the theme. I'm therefore at a loss as to why other Qt application follow the GTK theme, but Qt Creator and any application I make doesn't

Can anyone suggest what I should do to make the application use the GTK theme?

anda_skoa
8th November 2016, 22:05
If it works for other Qt applications but not your own, have the been built against the same Qt?

Otherwise the Qt version your app is using might lack the GTK platform theme plugin.

Cheers,
_

Assoluto
9th November 2016, 14:59
I'm using Qt 5.7 and the issue of programs not using the GTK theme isn't just with my application, but also with Qt Creator. It could be, as you suggest, that XnView MP and qBittorrent work because they were built with an earlier version of Qt (XnView MP uses 5.4).

If I run the below line on Linux the only styles it displays are Fusion and Windows, so, as you say, it looks like I don't have the GTK style.


QMessageBox::information(this, "Styles", QStyleFactory::keys().join(" "), QMessageBox::Ok);
However, according to this Qt blog post (http://blog.qt.io/blog/2012/10/30/cleaning-up-styles-in-qt5-and-adding-fusion/), the other styles have been deprecated and are no longer being developed, so using them probably isn't a good idea. Furthermore, the linked page for downloading older styles (https://codereview.qt-project.org/#/q/status:open+project:qt/qtstyleplugins,n,z) shows an empty directory, so it looks like the older styles aren't even available for download any more.

As things stand the linux version of the application look terrible, so I'd like to get them working with the GTK theme, but I still don't have a clue how to achieve this.

Any suggestions?

anda_skoa
9th November 2016, 18:03
I'm using Qt 5.7 and the issue of programs not using the GTK theme isn't just with my application, but also with Qt Creator. It could be, as you suggest, that XnView MP and qBittorrent work because they were built with an earlier version of Qt (XnView MP uses 5.4).

The version doesn't matter as much as how the version was built and which of its plugins are available.



If I run the below line on Linux the only styles it displays are Fusion and Windows, so, as you say, it looks like I don't have the GTK style.

I am not sure if there is an explicit, stand-alone GTK+ style, my guess is that this is provided by the GTK+ platform integration plugin or a platform theme plugin.



However, according to this Qt blog post (http://blog.qt.io/blog/2012/10/30/cleaning-up-styles-in-qt5-and-adding-fusion/), the other styles have been deprecated and are no longer being developed, so using them probably isn't a good idea.

Those are just the explicit styles shipped with Qt, the core idea is to adapt to the platform through platform plugins.

If you have installed these other two Qt applications through the distribution's installation mechanism, then they are built against the distributionn shipped Qt, which almost certainly comes with the integration plugins for GTK+ based environments.

You Qt version might not, or something might block the respective plugin from being loaded.

Cheers,
_