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. Using two stylesheets for the same widget
Forum Updated to NodeBB v4.3 + New Features

Using two stylesheets for the same widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 5 Posters 1.2k 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.
  • ivanicyI Offline
    ivanicyI Offline
    ivanicy
    wrote on last edited by
    #1

    Hello!! I need to have two versions of the same software. This versions change their colors so, I need to know if is it possible to give some condition to load the correct stylesheet.

    How can I do that?

    Thank you very much!

    jsulmJ 1 Reply Last reply
    0
    • ivanicyI ivanicy

      Hello!! I need to have two versions of the same software. This versions change their colors so, I need to know if is it possible to give some condition to load the correct stylesheet.

      How can I do that?

      Thank you very much!

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @ivanicy said in Using two stylesheets for the same widget:

      some condition

      What condition would it be?
      If you build different versions of your software you can decide at compile time what to use.
      You you check the condition at runtime and load the stylesheet accordingly.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • ivanicyI Offline
        ivanicyI Offline
        ivanicy
        wrote on last edited by
        #3

        I want to use a compilation variable in the .pro file. And then use it with #ifdef. The final purpose is: if I activate this variable, the application shows one color set and if I don't activate it, shows other color set.

        jsulmJ 1 Reply Last reply
        0
        • ivanicyI ivanicy

          I want to use a compilation variable in the .pro file. And then use it with #ifdef. The final purpose is: if I activate this variable, the application shows one color set and if I don't activate it, shows other color set.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @ivanicy See https://doc.qt.io/qt-5/qmake-variable-reference.html#defines

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • ivanicyI Offline
            ivanicyI Offline
            ivanicy
            wrote on last edited by
            #5

            Yes, I know how to configure a compilation variable, I need to know hoy to change the stylesheet of the application with this variable

            jsulmJ 1 Reply Last reply
            0
            • ivanicyI ivanicy

              Yes, I know how to configure a compilation variable, I need to know hoy to change the stylesheet of the application with this variable

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @ivanicy You already wrote how:

              #ifdef SOME_VARIABLE
              // Load stylesheet a
              #else
              // Load stylesheet b
              #endif
              

              Or wat exactly is the question?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              2
              • ivanicyI Offline
                ivanicyI Offline
                ivanicy
                wrote on last edited by
                #7

                Yes, but I want to know if it is possible to use this condition inside of the stylesheet in order to have only one stylesheet file

                jsulmJ 1 Reply Last reply
                0
                • ivanicyI ivanicy

                  Yes, but I want to know if it is possible to use this condition inside of the stylesheet in order to have only one stylesheet file

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @ivanicy It's not. But you could modify the stylesheet depending on that condition before loading it.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  2
                  • VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on last edited by
                    #9

                    You can use custom properties set in your widgets to decide what stylesheet to apply:
                    https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-using-dynamic-properties

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    ivanicyI 1 Reply Last reply
                    3
                    • ivanicyI Offline
                      ivanicyI Offline
                      ivanicy
                      wrote on last edited by
                      #10
                      This post is deleted!
                      1 Reply Last reply
                      0
                      • VRoninV VRonin

                        You can use custom properties set in your widgets to decide what stylesheet to apply:
                        https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-using-dynamic-properties

                        ivanicyI Offline
                        ivanicyI Offline
                        ivanicy
                        wrote on last edited by
                        #11

                        @VRonin Yes, I need something like that but for all widgets, like a "global" condition. Is it possible?

                        JonBJ 1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          Hi,

                          Since you have your stylesheet in a file, use a placeholder for the colour and before your set the stylesheet replace the placeholder with the value matching what you want.

                          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
                          3
                          • ivanicyI ivanicy

                            @VRonin Yes, I need something like that but for all widgets, like a "global" condition. Is it possible?

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by JonB
                            #13

                            @ivanicy
                            I do just what @SGaist has just suggested.

                            I don't like to maintain multiple files for different configurations, too much work. So to have stylesheets vary just by, say, color, I write one external stylesheet like

                             class1 { color: ##COLOR1##; }
                             widget2 { background-color: ##COLOR2##; }
                            

                            in as many places as necessary. Then because you have to read the stylesheet in via code to apply it anyway, it's simple to substitute the various ##...## sequences for whatever you need while you're doing so.

                            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