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
Qt 6.11 is out! See what's new in the release blog

[SOLVED] CSS change property from SLOT not working

Scheduled Pinned Locked Moved General and Desktop
11 Posts 2 Posters 2.9k 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
    #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