Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Linux - Support system's theme change
Qt 6.11 is out! See what's new in the release blog

Linux - Support system's theme change

Scheduled Pinned Locked Moved General and Desktop
16 Posts 4 Posters 10.5k Views 1 Watching
  • 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.
  • EddyE Offline
    EddyE Offline
    Eddy
    wrote on last edited by
    #2

    What happens if you set the style of your program in code?
    What style are you trying to use?

    Qt Certified Specialist
    www.edalsolutions.be

    1 Reply Last reply
    0
    • A Offline
      A Offline
      agarny
      wrote on last edited by
      #3

      If I programmatically set a style, e.g.
      @app->setStyle(new QPlastiqueStyle);@
      then the style is properly set, but it obviously doesn't respond to any change to the system's theme, and is therefore not what I want.

      In fact, I don't use and don't want to use any particular style. I just want my application to use the 'default' system style and respond to any change to it. Nothing more nothing less.

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #4

        The problem is, that your app runs on gnome and this is gtk and not Qt. If you use KDE, your app will use the system theme!

        1 Reply Last reply
        0
        • EddyE Offline
          EddyE Offline
          Eddy
          wrote on last edited by
          #5

          I've used kubuntu 10.10 in the past and there it's ok. But that's kde.

          Are you sure about that Scylla?
          It seems strange to me.

          A workaround could be to get the system style in code and set it like you did.

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #6

            Here it works as expected (Kubuntu 1010). If you don't use a hard coded style, it should work on KDE.

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #7

              You need to have a GTK style engine in Qt, so that Qt will use GTK styling by default. http://code.google.com/p/qgtkstyle/

              EDIT: Okay, that link is outdated. But anyway, that piece of code allows to use GTK styles in Qt, I don’t know where is instructions to use it.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                agarny
                wrote on last edited by
                #8

                For what it is worth, I quickly installed Kubuntu 11.04, and ran my application on it, and its look didn't match that of the KDE theme. Then again, I built my application on Ubuntu 11.04 and copied it over to my Kubuntu system, so it might explain...? (Note: I don't use any hard-coded style and, in fact, don't want to have to do that at all, since my application may end up being use on different flavours of Linux.)

                Eddy: what do you mean by "get the system style in code"?

                Smar: I have seen that Qt has QGtkStyle class, but on my Ubuntu box, QT_NO_STYLE_GTK is defined and therefore QGtkStyle is not available. Then again, as I mentioned before, I don't want to have to use styles. I would just hope that things would somehow work... :)

                1 Reply Last reply
                0
                • EddyE Offline
                  EddyE Offline
                  Eddy
                  wrote on last edited by
                  #9

                  Hi Alan,

                  There is an example called stylesheet that uses the solution I talked about.

                  @QString defaultStyle = QApplication::style()->metaObject()->className();@

                  have a look in the StyleSheetEditor constructor.

                  About Ubuntu 11.04 : I read that they are leaving gtk. Maybe this has something to do with it? Since prior versions of ubuntu didn't have this problem.

                  Qt Certified Specialist
                  www.edalsolutions.be

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    agarny
                    wrote on last edited by
                    #10

                    Thanks Eddy. I just had a quick look and for my application under Ubuntu 11.04, the following code:

                    @QRegExp regExp(".(.*)\+?Style");
                    QString defaultStyle = QApplication::style()->metaObject()->className();

                    qDebug() << "BEFORE:" << defaultStyle;

                    if (regExp.exactMatch(defaultStyle))
                    defaultStyle = regExp.cap(1);

                    qDebug() << "AFTER:" << defaultStyle;@

                    returns:

                    bq. BEFORE: "QCleanlooksStyle"
                    AFTER: "Cleanlooks"

                    This is already the style that my application uses, so I am not sure it helps...?

                    1 Reply Last reply
                    0
                    • EddyE Offline
                      EddyE Offline
                      Eddy
                      wrote on last edited by
                      #11

                      Did you try to set it in code using that string eventually? I suppose you did.
                      The reason why I ask is that you told us before that setting it using code went well.
                      If it's not, there must be a problem with the them I suppose on your system.

                      Qt Certified Specialist
                      www.edalsolutions.be

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        agarny
                        wrote on last edited by
                        #12

                        Well, I did try indeed (using app->setStyle(new QCleanlookStyle), even though app->style() would return QCleanLookStyle before I set the 'new' style.

                        Otherwise, I did say that hard setting the style worked in the sense that the style gets applied, but I also said that if I change the theme, then my application doesn't respond to the change.

                        As I also said, the Qt examples behave the same as my application (i.e. don't respond to a change in the theme) while Qt Creator works as expected (i.e. responds to a change in the theme).

                        1 Reply Last reply
                        0
                        • EddyE Offline
                          EddyE Offline
                          Eddy
                          wrote on last edited by
                          #13

                          Sorry it couldn't help you out. It was worth trying I guess.

                          Qt Certified Specialist
                          www.edalsolutions.be

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            agarny
                            wrote on last edited by
                            #14

                            No worries, and yes always worth trying. I guess that if I was to study Qt Creator's source code carefully, then I would find out how they do it...

                            1 Reply Last reply
                            0
                            • EddyE Offline
                              EddyE Offline
                              Eddy
                              wrote on last edited by
                              #15

                              Sounds like a good idea. And you could learn other usefull things.

                              Keep us posted.

                              Qt Certified Specialist
                              www.edalsolutions.be

                              1 Reply Last reply
                              0
                              • A Offline
                                A Offline
                                agarny
                                wrote on last edited by
                                #16

                                Oh, I already have from Qt Creator's source code. :) It's just that I am still struggling about the overall structure of the source code, so I tend to use it as a last resource.

                                1 Reply Last reply
                                0

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt
                                • Unsolved