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. [SOLVED] CSS change property from SLOT not working

[SOLVED] CSS change property from SLOT not working

Scheduled Pinned Locked Moved General and Desktop
11 Posts 2 Posters 2.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.
  • R Offline
    R Offline
    rfringuello89
    wrote on last edited by
    #1

    Hi, I need to apply a CSS rule to my QSlider using properties but I am not able to do it in a SLOT (where I need to do it!) however I can do it in another function (called from the constructor).

    This is where I set my CSS (in the constructor):
    @this->setStyleSheet("QWidget{background:rgba(246,246,246,246);}"

                        "QSlider{background: transparent; width: 50px; height:20px; border-radius: 10px}"
                        "::groove:horizontal {"
                            "height: 20px;"
                            "border-radius:10px;"
                        "}"
                        "::handle:horizontal {"
                            " background: rgb(245,246,248);"
                            " border: 1px solid rgb(220,220,220);"
                            "height: 20px;"
                            " width: 20px;"
                            " border-radius: 10px;"
                        "}"
                        "::add-page:horizontal {"
                            "background: rgb(212,212,212);"
                            "height: 20px;"
                            "border-top-right-radius: 10px;"
                            "border-bottom-right-radius: 10px;"
                        "}"
                        "::sub-page:horizontal[state=\"false\"]{"
                            "background: rgb(251,165,0);"
                            "border-top-left-radius: 10px;"
                            "border-bottom-left-radius: 10px;"
                        "}"
    
                        "::sub-page:horizontal[state=\"true\"]{"
                            "background: red;"
                            "border-top-left-radius: 10px;"
                            "border-bottom-left-radius: 10px;"
                        "}"
    
                        );@
    

    and this is what I do in my slot:
    @ ui.slider1->setProperty("state", true);
    ui.slider2->setProperty("state", true);
    ui.slider3->setProperty("state", false);@

    I need to apply the "state" property in the slot but it is ignored while the other properties are applied correctly.

    Can anyone help me?

    Thanks a lot

    1 Reply Last reply
    0
    • R Offline
      R Offline
      rfringuello89
      wrote on last edited by
      #2

      Solved doing a first setProperty in the other method then it works in the slot!

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

        Hi,

        Since it's a static style sheet, why don't you apply it directly in the constructor ?

        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
        • R Offline
          R Offline
          rfringuello89
          wrote on last edited by
          #4

          bq. This is where I set my CSS (in the constructor):
          bq. this->setStyleSheet("QWidget{background:rgba(246,246,246,246);}"
          bq. ......

          As I said, I set the style sheet in the constructor while at runtime I set the correct "state" property. It works but I need to set the property twice in order to see it applied like:
          @ ui.slider1->setProperty("state", true);
          ui.slider1->setProperty("state", true);

          @

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

            Sorry, I missed the parenthesis about the constructor.

            Do you initialize the state property ?

            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
            • R Offline
              R Offline
              rfringuello89
              wrote on last edited by
              #6

              How should I initialize it?

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

                That's up to you know what is a sensible default value. Probably false ?

                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
                • R Offline
                  R Offline
                  rfringuello89
                  wrote on last edited by
                  #8

                  Oh sure! I didn't understand what you meant!
                  Yes I am initializing it in an init() method called by the constructor!

                  @ui.slider1->setProperty("state", false);@

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

                    I thought I was forgetting something… "Here":http://qt-project.org/wiki/DynamicPropertiesAndStylesheets you have the technique

                    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
                    • R Offline
                      R Offline
                      rfringuello89
                      wrote on last edited by
                      #10

                      Well, I solved the problem. I was using that post to learn how to do it but I wasn't doing this:
                      @tstFrame->setProperty("error",true);
                      tstFrame->style()->unpolish(tstFrame);
                      tstFrame->style()->polish(tstFrame);
                      tstFrame->update();@

                      because when I started this thread I tried that piece of code but I had many errors (I don't remember which ones) and I thought it was for older versions of QT :(

                      Thanks :D

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

                        You're welcome !

                        Since you have your stilling in place now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

                        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

                        • Login

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