Use GTK Theme On Linux?

  • When I run my application on Linux Mint it doesn't use the installed GTK theme. Other Qt applications installed from the Mint repository do use the GTK theme, but I'm not sure how to make application work this way.

    I tried building Qt from the source code on Linux Mint, but even with that Qt build the application still does not use the GTK theme.

    What do you have to do to make the application use the GTK theme?

  • You can set the style from main():

    #include <QApplication>
    #include <QStyleFactory>
    int main(int argc, char *argv[])
        QApplication app(argc, argv);

    The options for styles (themes) change from Qt 4.x to 5.x. Many of the old ones were removed from Qt5 such as 'cleanlooks' which was one I really liked. There was the old Athena style that was removed as well (from the old unix systems) which nobody used anymore as far as I know.

    For the style options you have 'windows' and 'fusion' on all platforms. Depending on the OS, 'windowsxp', 'windowsvista', 'gtk' and 'macintosh' may be available (this is from the Qt help file). In your case you want 'gtk'. The name is case sensitive.

    You shouldn't need to set this if you want to match what the OS is currently using. For example, on OS X I don't set the style but I end up with something that mimics aqua (macintosh style). If I was running on WinXP and didn't set a specific style I would expect something that looks like what you would expect on WinXP.

    I suspect the older programs you have were probably running Qt4. If I remember correctly there was a GTK theme that could be used even if the desktop wasn't using this style or theme (?).

    I found 'fusion' is pretty good if nothing else. Maybe there is a style plugin version of GTK that you could use if you had to (?).

  • I tried that, but unfortunately the application still isn't using the OS GTK theme.

    @Rondog said in Use GTK Theme On Linux?:

    You shouldn't need to set this if you want to match what the OS is currently using.

    That's what I was hoping to achieve, but my Qt applications are ignoring the OS GTK theme. Here's a screenshot to show what my GTK theme looks like:

    alt text

    And here's how Qt applications I build look:

    alt text

    As you can see the OS GTK theme isn't being applied. The GTK theme also doesn't get applied to Qt Creator, though it does get applied to Qt applications that I download from the Mint repository.

    I hoped building Qt on Mint would solve the problem, but even when using that Qt build applications still don't get the GTK theme applied.

    I made the very simple Test program shown in the above screenshot to make sure it wasn't an issue with my code, but that also has the same problem.

    I'm not sure why this is happening or what to do to fix it.

  • Lifetime Qt Champion


    Likely, because the plugin is built for your distribution provided Qt. If you use that one to build your application then you should have it applied as you want it.

  • Thanks for the advice, but I'm not quite following. From what you say I need a plugin to make the application use the OS GTK theme?

    Could you tell me what the plugin is called or where to download it? Or is it something that comes with the Linux distribution

    Sorry if I'm being stupid. I'm new to Qt and not very knowledgeable about Linux so I'm a bit confused :)

  • Lifetime Qt Champion

    AFAIK, it's name of the plugin itself is qgtk3 but it's likely already installed.

    One thing you can do is start your application with QT_DEBUG_PLUGINS set to 1 so you'll see what is happening with the plugins at load time.

  • This is the output of running the Test program pictured earlier with QT_DEBUG_PLUGINS:

    Is there a way to force the GTK plugin to load? If not, what would be the best way to resolve the issue?

  • Lifetime Qt Champion

    Can you check whether you have the plugin in your Qt installation ?

    If not, then you can build it (just the plugin not the whole of Qt) to add it to your Qt version. You can get the sources from the maintenance tool.

  • I checked and libqgtk3 is missing from the .../plugins/platforms directory with the 5.7.0 offline installer.

    Searching on Google I found a bug report that also says it's missing, though it has been closed as "out of scope":

    I downloaded 5.7.1 offline installer, but it's missing there as well.

    I tried running the maintenance tool, but there are no default repositories added with the Qt offline installer (which is another issue reported elsewhere).

    I therefore downloaded the online installer, which installed 5.7.1, but once again libqgtk3 was missing, so applications still didn't use the GTK theme.

    I tried running the maintance tool that was installed with the online installer and did a full update of Qt, but still libqgtk3 was not installed.

    Looking at some posts online, other people report that libqgtk2 was present in 5.6 but there's nothing with 5.7:

    libqgtk2/3 also doesn't get built when you build the Qt 5.7.0 from the source code.

    It's strange that they've removed such an important feature in 5.7.

    I can't find libqgtk2/3 available for download separately anywhere. I'll try downloading Qt 5.6 and see if it's included with that.

  • I just tried Qt 5.6.2 and that works correctly:

    alt text

    I don't understand why they removed libqgtk plugin from 5.7, since it is a rather essential component.

    I'm not sure what to do now, but the best option appears to be to use 5.6.2.

    As a side note, the Qt Creator that comes with 5.6.2 also looks a lot nice because it uses my GTK theme, while the 5.7 Qt Creator doesn't and looks terrible.

  • Lifetime Qt Champion

    If you read the complete bug report, it will be back with 5.8.

    In between, like I already suggested, you can build the plugin yourself. You need to install the corresponding dependencies on your system.

  • I'll stick with Qt 5.6.2 until 5.8 is released.

    Thanks a lot for all you help SGaist. I didn't have a clue what was going wrong and wouldn't have found the source of the problem with your assistance.

    Thanks again.

Log in to reply