Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Use GTK Theme On Linux?

Use GTK Theme On Linux?

Scheduled Pinned Locked Moved Solved General and Desktop
linuxgtk
12 Posts 3 Posters 8.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Elsworth55
    wrote on 12 Jan 2017, 14:05 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rondog
      wrote on 12 Jan 2017, 17:34 last edited by Rondog 1 Dec 2017, 17:36
      #2

      You can set the style from main():

      #include <QApplication>
      #include <QStyleFactory>
      
      int main(int argc, char *argv[])
      {	
          QApplication app(argc, argv);
          QApplication::setStyle(QStyleFactory::create("gtk"));
      ...
      

      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 (?).

      E 1 Reply Last reply 12 Jan 2017, 20:51
      2
      • R Rondog
        12 Jan 2017, 17:34

        You can set the style from main():

        #include <QApplication>
        #include <QStyleFactory>
        
        int main(int argc, char *argv[])
        {	
            QApplication app(argc, argv);
            QApplication::setStyle(QStyleFactory::create("gtk"));
        ...
        

        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 (?).

        E Offline
        E Offline
        Elsworth55
        wrote on 12 Jan 2017, 20:51 last edited by
        #3

        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.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 12 Jan 2017, 21:25 last edited by
          #4

          Hi,

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • E Offline
            E Offline
            Elsworth55
            wrote on 12 Jan 2017, 21:56 last edited by
            #5

            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 :)

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 12 Jan 2017, 22:02 last edited by
              #6

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • E Offline
                E Offline
                Elsworth55
                wrote on 12 Jan 2017, 23:39 last edited by
                #7

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

                http://pastebin.com/K0P5imT0

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

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 13 Jan 2017, 07:56 last edited by
                  #8

                  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.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  2
                  • E Offline
                    E Offline
                    Elsworth55
                    wrote on 13 Jan 2017, 14:53 last edited by
                    #9

                    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":

                    https://bugreports.qt.io/browse/QTBUG-52259

                    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:

                    https://github.com/probonopd/AppImages/issues/102

                    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.

                    1 Reply Last reply
                    1
                    • E Offline
                      E Offline
                      Elsworth55
                      wrote on 13 Jan 2017, 15:56 last edited by Elsworth55
                      #10

                      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.

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 13 Jan 2017, 21:01 last edited by
                        #11

                        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.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        2
                        • E Offline
                          E Offline
                          Elsworth55
                          wrote on 13 Jan 2017, 22:10 last edited by
                          #12

                          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.

                          1 Reply Last reply
                          1

                          9/12

                          13 Jan 2017, 14:53

                          • Login

                          • Login or register to search.
                          9 out of 12
                          • First post
                            9/12
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved