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 Offline
    Sh1gsS Offline
    Sh1gs
    wrote on last edited by
    #1

    Hello all,

    First, I apologize if this has been asked/answered before. I am creating a simple application with various widgets, buttons, etc on it and am just playing around with stylesheets. For the most part, everything is working correctly except the font for QRadioButton. I have the following:

    QRadioButton::checked{
    color: rgb(255,255,60);
    font-weight:bold;
    }
    

    The color changes appropriately when the radio button is selected, but the font remains the same. I have even tried adding:

    QRadioButton{
    font-weight: normal;
    }
    

    but that doesn't seem to work either. What am I missing?

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

      Hi,

      What version of Qt are you using ?
      On what platform ?
      Do you have any other stylesheet in your application ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Sh1gsS 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        What version of Qt are you using ?
        On what platform ?
        Do you have any other stylesheet in your application ?

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

        @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 raven-worxR 2 Replies 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.

          JonBJ Online
          JonBJ Online
          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 Online
                JonBJ Online
                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 Online
                    JonBJ Online
                    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 Online
                            JonBJ Online
                            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 Online
                                JonBJ Online
                                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