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. QRadioButton stylesheet font:bold doesn't work?
Forum Updated to NodeBB v4.3 + New Features

QRadioButton stylesheet font:bold doesn't work?

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 5 Posters 10.2k Views 4 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.
  • Sh1gsS Sh1gs

    @SGaist

    Hello, I am using version 5.9.5 on Windows. I'm doing it in a clunky way, because I just want to see how things work, so I have a header file with the following:

    static QString RBStyle = QString(
    "QWidget{ " \
    "background-color:  rgb();" \
    "color: rgb();" \
    "}"
    "QRadioButton::checked{" \
    "color: rgb(255,255,60);" \
    "font-weight:bold;" \
    "}"
    );
    

    and then in my .cpp file I put:

    this->setstylesheet(RBStyle);
    

    I realize using a .qss file would be better, but for the purpose of just messing around, I did it this way. Everything else I put seems to work, font just doesn't for whatever reason.

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

    @Sh1gs
    https://stackoverflow.com/questions/37802571/how-to-use-qss-to-set-radio-button-bold-when-checked is reporting the same kind of problem as you. Although the OP seems to say the solutions did not work, I think you should read through and just try them!

    1 Reply Last reply
    0
    • Sh1gsS Sh1gs

      @SGaist

      Hello, I am using version 5.9.5 on Windows. I'm doing it in a clunky way, because I just want to see how things work, so I have a header file with the following:

      static QString RBStyle = QString(
      "QWidget{ " \
      "background-color:  rgb();" \
      "color: rgb();" \
      "}"
      "QRadioButton::checked{" \
      "color: rgb(255,255,60);" \
      "font-weight:bold;" \
      "}"
      );
      

      and then in my .cpp file I put:

      this->setstylesheet(RBStyle);
      

      I realize using a .qss file would be better, but for the purpose of just messing around, I did it this way. Everything else I put seems to work, font just doesn't for whatever reason.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #5

      @Sh1gs
      some thoughts from my side:

      1. using a :: in a selector specifies a sub-control of the element, But there is no checked subcontrol. You should rather use :checked. (Even though the official stylesheet docs seem to wrongly mix it up). But i am wondering that it works with the sub-control selector.
      2. Try to unset the font-weight with a QRadioButton:unchecked selector

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      Sh1gsS 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @Sh1gs
        some thoughts from my side:

        1. using a :: in a selector specifies a sub-control of the element, But there is no checked subcontrol. You should rather use :checked. (Even though the official stylesheet docs seem to wrongly mix it up). But i am wondering that it works with the sub-control selector.
        2. Try to unset the font-weight with a QRadioButton:unchecked selector
        Sh1gsS Offline
        Sh1gsS Offline
        Sh1gs
        wrote on last edited by
        #6

        @raven-worx

        By that thinking, then when the radiobutton is selected, the color shouldn't change, but it does. Changing it to : from :: didn't work either. I also tried ::unchecked to set the font weigh to normal and that didn't work :( I don't know what else to try. I've tried font, font-weight, font-style, and nothing seems to change the font to bold

        Ultimately, I'm fiddling with stylesheets for a work project and would like to find a way to make this happen.

        JonBJ 1 Reply Last reply
        0
        • Sh1gsS Sh1gs

          @raven-worx

          By that thinking, then when the radiobutton is selected, the color shouldn't change, but it does. Changing it to : from :: didn't work either. I also tried ::unchecked to set the font weigh to normal and that didn't work :( I don't know what else to try. I've tried font, font-weight, font-style, and nothing seems to change the font to bold

          Ultimately, I'm fiddling with stylesheets for a work project and would like to find a way to make this happen.

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

          @Sh1gs
          At this point you should get rid of any :checked etc. in the selector and just try an unconditional

          "QRadioButton {" \
          "font-weight:bold;" \
          "}"
          

          I imagine you will say this does not bold for you, and so we can eliminate anything about the :checked qualifier being of any relevance.

          P.S.
          Give a quick desperation try to font-weight:700;" instead of bold, just in case....

          Sh1gsS 1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #8

            Hi
            It seems the states checked unchecked do not use any font statements included.
            alt text

            They react fine to color change but any font statements seems to be ignored.
            However, its does use its font inherited from QWidget as
            targeting that, font is changed.
            Also using RadioButton alone

            
            QRadioButton {
            font: 750 24pt "Arial";
            }
            
            

            So bascially im not sure its possible to make it go bold on checked using
            stylesheets alone.

            JonBJ Sh1gsS 2 Replies Last reply
            2
            • mrjjM mrjj

              Hi
              It seems the states checked unchecked do not use any font statements included.
              alt text

              They react fine to color change but any font statements seems to be ignored.
              However, its does use its font inherited from QWidget as
              targeting that, font is changed.
              Also using RadioButton alone

              
              QRadioButton {
              font: 750 24pt "Arial";
              }
              
              

              So bascially im not sure its possible to make it go bold on checked using
              stylesheets alone.

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

              @mrjj
              That is indeed how it was beginning to look. (Though I see some old web posts where users claim bold does work, some do not, various Qt versions.)

              So you should try font-style: italic, and other individual font- styles, to verify just which style attribute(s) are affected. Before you check through the Qt source code (it's to do with font in QRadioButton, so it can't be hard to find) and raise a bug report depending on what you find :)

              1 Reply Last reply
              1
              • JonBJ JonB

                @Sh1gs
                At this point you should get rid of any :checked etc. in the selector and just try an unconditional

                "QRadioButton {" \
                "font-weight:bold;" \
                "}"
                

                I imagine you will say this does not bold for you, and so we can eliminate anything about the :checked qualifier being of any relevance.

                P.S.
                Give a quick desperation try to font-weight:700;" instead of bold, just in case....

                Sh1gsS Offline
                Sh1gsS Offline
                Sh1gs
                wrote on last edited by
                #10

                @JonB

                Using the unconditional, the text changes color AND gets bolded properly.

                1 Reply Last reply
                0
                • mrjjM mrjj

                  Hi
                  It seems the states checked unchecked do not use any font statements included.
                  alt text

                  They react fine to color change but any font statements seems to be ignored.
                  However, its does use its font inherited from QWidget as
                  targeting that, font is changed.
                  Also using RadioButton alone

                  
                  QRadioButton {
                  font: 750 24pt "Arial";
                  }
                  
                  

                  So bascially im not sure its possible to make it go bold on checked using
                  stylesheets alone.

                  Sh1gsS Offline
                  Sh1gsS Offline
                  Sh1gs
                  wrote on last edited by
                  #11

                  @mrjj

                  Reading through the Help files, QPushButton has the ability to customize the font. Both are box models, why do you think QRadioButton doesn't do it?

                  mrjjM 1 Reply Last reply
                  0
                  • Sh1gsS Sh1gs

                    @mrjj

                    Reading through the Help files, QPushButton has the ability to customize the font. Both are box models, why do you think QRadioButton doesn't do it?

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #12

                    @Sh1gs
                    hi
                    well it does respond to font ,
                    but not in ::checked ::unchecked
                    as far as i could see from testing.
                    The states clearly work as the color was changed
                    but regardless of font statement used in those
                    states, i didn't see any effect even same font statement worked
                    with no state syntax.
                    So its either a bug, or simply not support for such states.

                    JonBJ 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      @Sh1gs
                      hi
                      well it does respond to font ,
                      but not in ::checked ::unchecked
                      as far as i could see from testing.
                      The states clearly work as the color was changed
                      but regardless of font statement used in those
                      states, i didn't see any effect even same font statement worked
                      with no state syntax.
                      So its either a bug, or simply not support for such states.

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

                      @mrjj , @Sh1gs
                      I did reference https://stackoverflow.com/questions/37802571/how-to-use-qss-to-set-radio-button-bold-when-checked above, which is exactly the situation you are reporting.

                      The "solution" there is only in a comment:

                      At the end, I use a property to indicate the font bold / normal and setProperty in the slot function. It worked! I wonder the difference between property and checked state

                      if you can figure what that OP means he did by this and it works for you.

                      raven-worxR 1 Reply Last reply
                      1
                      • JonBJ JonB

                        @mrjj , @Sh1gs
                        I did reference https://stackoverflow.com/questions/37802571/how-to-use-qss-to-set-radio-button-bold-when-checked above, which is exactly the situation you are reporting.

                        The "solution" there is only in a comment:

                        At the end, I use a property to indicate the font bold / normal and setProperty in the slot function. It worked! I wonder the difference between property and checked state

                        if you can figure what that OP means he did by this and it works for you.

                        raven-worxR Offline
                        raven-worxR Offline
                        raven-worx
                        Moderators
                        wrote on last edited by raven-worx
                        #14

                        @JonB said in QRadioButton stylesheet font:bold doesn't work?:

                        if you can figure what that OP means he did by this and it works for you.

                        Probably this:

                        QRadioButton[checked="true"] {
                           font-weight: bold;
                        }
                        

                        additionally to that you could try:

                        connect( radioButton, &QRadioButton::toggled, this, [radioButton]() { 
                            radioButton->style()->polish(radioButton);
                        } );
                        

                        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                        If you have a question please use the forum so others can benefit from the solution in the future

                        JonBJ 1 Reply Last reply
                        3
                        • raven-worxR raven-worx

                          @JonB said in QRadioButton stylesheet font:bold doesn't work?:

                          if you can figure what that OP means he did by this and it works for you.

                          Probably this:

                          QRadioButton[checked="true"] {
                             font-weight: bold;
                          }
                          

                          additionally to that you could try:

                          connect( radioButton, &QRadioButton::toggled, this, [radioButton]() { 
                              radioButton->style()->polish(radioButton);
                          } );
                          
                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by
                          #15

                          @raven-worx
                          I do think the OP here should try just that.

                          However, the way the OP phrased what he wrote in the stackoverflow comment:

                          I use a property to indicate the font bold / normal and setProperty in the slot function.

                          might suggest he had to use a dynamic property (other than checked), which he added/removed or switched on/off in the stateChanged slot handler, to "shadow" the :checked state and get it to work with font change....

                          1 Reply Last reply
                          1

                          • Login

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