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. How to save style before changing it?
Forum Updated to NodeBB v4.3 + New Features

How to save style before changing it?

Scheduled Pinned Locked Moved General and Desktop
21 Posts 7 Posters 8.4k 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.
  • G Offline
    G Offline
    goetz
    wrote on last edited by
    #11

    [quote author="fluca1978" date="1323090473"]Of course style is shared among the whole application. The problem here was also about how to swtich back to an already used style.[/quote]

    That was one part. The other question was

    [quote author="Asperamanca" date="1323078786"]What I want is

    • to be able to explicitly set the old style on certain widgets[/quote]

    http://www.catb.org/~esr/faqs/smart-questions.html

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

      You can set a style on a widget too. That is not the issue:
      @
      QWidget::setStyle(theOtherStyle);
      @
      Setting a style on a widget will override the application style.

      However, I guess you should heed the warning from the documentation:
      [quote]Warning: This function is particularly useful for demonstration purposes, where you want to show Qt's styling capabilities. Real applications should avoid it and use one consistent GUI style instead.[/quote]

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #13

        Well, I could do an ugly hack like this:

        @
        if (qobject_cast<QWindowsVistaStyle*>(QApplication::style()))
        {
        sm_pLocalStyle = new QWindowsVistaStyle();
        }
        else if (qobject_cast<QWindowsXPStyle*>(QApplication::style()))
        {
        sm_pLocalStyle = new QWindowsXPStyle();
        }
        else
        {
        sm_pLocalStyle = new QWindowsStyle();
        }
        @

        1 Reply Last reply
        0
        • B Offline
          B Offline
          broadpeak
          wrote on last edited by
          #14

          [quote author="Andre" date="1323093315"]
          Setting a style on a widget will override the application style.
          [/quote]

          The widget style is usually the same for all widgets in an application (QApplication::style()), but it can be overridden on a per-widget basis using QWidget::setStyle().

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #15

            Well, QStyle is an QObject, so retrieving the name of the current style is as simple as ...
            @
            QString currentStyle = qApp->style()->metaObject()->className(); // eg. 'QWindowsVistaStyle'
            @

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

              But the class name is not the same as the style name, that you need to instantiate it. Although, I think you might be able to instantiate the object using the class name.

              1 Reply Last reply
              0
              • V Offline
                V Offline
                veeeee_d
                wrote on last edited by
                #17

                You can deep copy the style and just restore it later, can't you?

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  lgeyer
                  wrote on last edited by
                  #18

                  [quote author="veeeee_d" date="1323105034"]You can deep copy the style and just restore it later, can't you?[/quote]

                  You can't clone a QObject.

                  [quote author="Andre" date="1323104776"]But the class name is not the same as the style name, that you need to instantiate it. Although, I think you might be able to instantiate the object using the class name. [/quote]

                  What's the difference between the style name and the class name? What's the advantage of one over the other?

                  As far as I've seen QStyle unfortunately does not provide any invokable constructors so you'll need a simple factory which creates a QStyle out of a given (class) name.

                  (I wonder why QObject subclasses do not have at least one invokable (default) constructor.)

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #19

                    Indeed, that would solve the issue. I also wonder why the QStyle classes don't have a method like styleName() that returns the name of the style that you can pass to QApplication::setStyle(QString name). The difference between the class and the style name is at least the "Q", but perhaps more.

                    By the way: I noticed the same types of missing features for the Qt SQL drivers: all you can get is a list of plugin names for the drivers, but nothing that you might want to present to the end user.

                    One final issue that comes to mind is this: are you (topic starter) certain that it actualy works to change the style during the application run? Because I think that that is not really supported. The docs for QApplication::setStyle() even suggest you set it before you actually construct the QApplication object. That makes me wonder how dynamic style changes are going to be. I never tried it myself, but it would not supprise me that dynamic style changes are not supported at all, and you run into all kinds of layout and rendering issues if you try.

                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      veeeee_d
                      wrote on last edited by
                      #20

                      Or maybe they could be exported as a Style Sheet, but I believe that would be a little complicated to develop.

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        Asperamanca
                        wrote on last edited by
                        #21

                        Quite a thread, for such a simple question!

                        My main issue is that my application is a little schizophrenic:

                        Within the main window's client area, it is a simulation of how it would run on the embedded device, with a corresponding style.

                        Outside that (the menu bar, dialogs that are only used on the PC), it should look and behave like a good desktop application.

                        I need the style that is used on the embedded device to properly test the configuration on the PC. On the other hand, I need the dialogs and menus to at least work in the PC. Setting the style manually on the widgets that should have the "PC style" sounded like the best approach.

                        However, I have found out that my main troubles did not come from the style at all...it came from the palette. Somehow, I implicitly assumed that the palette would be part of the style. It is not.

                        So I could solve most of my troubles by copying the palette before changing it, and setting that palette on the "PC widgets". Fortunately, a palette can be copied easily.

                        Thanks all for discussing and making suggestions!

                        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 Extensions
                        • Unsolved