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. Undoing an added "setStyleSheet" property
Qt 6.11 is out! See what's new in the release blog

Undoing an added "setStyleSheet" property

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 5 Posters 7.7k Views 2 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.
  • jazzycamelJ jazzycamel

    I don't know if the CSS 'initial' and/or 'unset' values work with Qt stylesheets, might be worth a try? For example:

    setStyleSheet("background-color: initial;");
    

    or

    setStyleSheet("background-color: unset;");
    
    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #6

    @jazzycamel
    This looked good, and is a reasonable answer to the question!

    However, in my case both of these resulted in the QTextEdit's going black, which is not good given that the text on it is black too :) I'm guessing that somewhere else (like the app's global stylesheet which the code reads in and applies) there is some default entry which sets all QTextEdits' default background color to something else, and initial/unset reverts to some other base, default color, losing that :(

    So a possible good answer, but in my case it really does look like I need to either remove or alter the background-color (only) explicitly on the widget...?

    1 Reply Last reply
    0
    • jazzycamelJ Offline
      jazzycamelJ Offline
      jazzycamel
      wrote on last edited by
      #7

      Thats a shame, maybe consider raising a feature request for that one.

      Seems to me that saving and restoring the original stylesheet might be the only way to then.

      For the avoidance of doubt:

      1. All my code samples (C++ or Python) are tested before posting
      2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
      JonBJ 1 Reply Last reply
      0
      • jazzycamelJ jazzycamel

        Thats a shame, maybe consider raising a feature request for that one.

        Seems to me that saving and restoring the original stylesheet might be the only way to then.

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

        @jazzycamel
        Yep, at present that seems to be the only route.

        setStyleSheet principle could do with a couple of enhancements:

        1. appendToStyleSheet(str). Adds some more stuff to the existing stylesheet without requiring you to fetch its current content and then reset the whole thing. Having said that, there are calls to fetch->change->settonew, so it's only really a convenience.

        2. From a setStyleSheet, I assume that at some level Qt parses the properties string into its constituent properties to set. Make it so the individual properties can then be accessed directly, e.g. QWidget::setStyleProperty("background-color", newValue) or QWidget::removeStyleProperty("background-color").

        At the moment, because there's only a setStyleSheet, the code I have inherited is full of code in different modules using this, and who knows whether that will overwrite other deliberate changes from elsewhere. It doesn't lend itself to safe, self-contained programming features.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Vadi2
          wrote on last edited by
          #9

          Chances of this happening, apart from a contribution to Qt, are pretty slim though. The roadmap is currently fascinated with QML, customising QtWidgets is on the wayside.

          JonBJ 1 Reply Last reply
          0
          • Vinod KuntojiV Offline
            Vinod KuntojiV Offline
            Vinod Kuntoji
            wrote on last edited by
            #10

            @JNBarchan ,
            To undo the stylesheet, you can use
            textEdit->setStylesheet("");

            C++, Qt, Qt Quick Developer,
            PthinkS, Bangalore

            JonBJ 1 Reply Last reply
            0
            • V Offline
              V Offline
              Vadi2
              wrote on last edited by
              #11

              That would undo the whole stylesheet - not what the topic is looking for. OP is interested in undoing 1 property.

              1 Reply Last reply
              1
              • Vinod KuntojiV Vinod Kuntoji

                @JNBarchan ,
                To undo the stylesheet, you can use
                textEdit->setStylesheet("");

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

                @Vinod-Kuntoji
                As @Vadi2 has just said, the whole point of the question is how to selectively modify certain individual property assignments which may have been made previously, without altering any others.

                1 Reply Last reply
                0
                • V Vadi2

                  Chances of this happening, apart from a contribution to Qt, are pretty slim though. The roadmap is currently fascinated with QML, customising QtWidgets is on the wayside.

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

                  @Vadi2 said in Undoing an added "setStyleSheet" property:

                  Chances of this happening, apart from a contribution to Qt, are pretty slim though. The roadmap is currently fascinated with QML, customising QtWidgets is on the wayside.

                  Although I am a total noob to Qt, I read yesterday (somewhere...) that actually the roadmap now is to sideline development on QML, because it has received so much attention, and concentrate on new features for Widgets, to bring them back up to speed!

                  1 Reply Last reply
                  1
                  • Vinod KuntojiV Offline
                    Vinod KuntojiV Offline
                    Vinod Kuntoji
                    wrote on last edited by
                    #14

                    @Vadi2 ,@JNBarchan

                    Ya, I can undo only the 1 property without altering others. I hope you got the solution.

                    ui->textEdit->setStyleSheet("background-color:red;font-size:12pt;");

                    ui->textEdit->setStyleSheet("background-color:none;font-size:12pt;");

                    C++, Qt, Qt Quick Developer,
                    PthinkS, Bangalore

                    JonBJ 1 Reply Last reply
                    0
                    • Vinod KuntojiV Vinod Kuntoji

                      @Vadi2 ,@JNBarchan

                      Ya, I can undo only the 1 property without altering others. I hope you got the solution.

                      ui->textEdit->setStyleSheet("background-color:red;font-size:12pt;");

                      ui->textEdit->setStyleSheet("background-color:none;font-size:12pt;");

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

                      @Vinod-Kuntoji
                      That does not just alter the background-color property, as I might want. That alters the whole of the stylesheet, and relies on knowledge that font-size has been set to 12pt to set that too, information which is not available to me in the generic case I have described (e.g. some other piece of code somewhere has set it, which I would not be aware of). If you read what I have asked you will see this is explained, as others understand.

                      Furthermore (I think), background-color:none does not "undo" background-color:red: it explicitly sets it to "none", which will override the color from elsewhere, whereas in this case what I wish to do is remove the explicit specification of any background-color on the widget. However, that is by-the-by to the central point described in the paragraph above.

                      1 Reply Last reply
                      0
                      • JonBJ JonB referenced this topic on

                      • Login

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