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. Center align text in radio button

Center align text in radio button

Scheduled Pinned Locked Moved General and Desktop
14 Posts 7 Posters 18.2k 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.
  • G Offline
    G Offline
    giesbert
    wrote on last edited by
    #2

    you could try it, using a style sheet:

    @
    QString szStyle = "QRadioButton {text-align: left;}";

    pRadio->setStyleSheet(szStyle);
    

    @

    Nokia Certified Qt Specialist.
    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

    1 Reply Last reply
    0
    • G Offline
      G Offline
      gauravofindia
      wrote on last edited by
      #3

      Gerolf, but how do i center align the text.

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vcsala
        wrote on last edited by
        #4

        Have you tried to replace left to center in Gerolf's sample?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          gauravofindia
          wrote on last edited by
          #5

          How do define pRadio and in which file?

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DenisKormalev
            wrote on last edited by
            #6

            pRadio is your QRadioButton object.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #7

              Or set the stylesheet in Qt Designer or the designer view of Qt Creator.

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • N Offline
                N Offline
                NDev
                wrote on last edited by
                #8

                QRadioButton {text-align: center;} didn't work for me. I am not sure if QT picks text-align for QRadioButton.

                I was able to get the indicator center align, however then the text is left align to the indicator, so it is on the center but not properly align.

                All I want is to center align the text as it gets for indicator.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #9

                  I don't think you can do that. Perhaps you could work around it by using a QRadioButton without a label, a QLabel that is centered and and put them in a horizontal layout together?

                  1 Reply Last reply
                  0
                  • ? This user is from outside of this forum
                    ? This user is from outside of this forum
                    Guest
                    wrote on last edited by
                    #10

                    not sure if text-align will be recognized.
                    Other approaches I'd try:

                    1. You can create your own complex control as stated above

                    2. You can play with this: "http://developer.qt.nokia.com/faq/answer/how_can_i_draw_custom_subcontrols_for_a_complex_control":http://developer.qt.nokia.com/faq/answer/how_can_i_draw_custom_subcontrols_for_a_complex_control

                    3. can play with values below and get close to what you want ...
                      @
                      QRadioButton {
                      spacing: 5px;
                      }
                      QRadioButton::indicator {
                      width: 50px;
                      height: 13px;
                      }
                      @

                    4. You can try to edit/extend gui module to support this ...
                      see qcommonstyle.cpp and qstylesheetstyle.cpp, SE_RadioButtonIndicator and SE_RadioButtonLableSpacing are of interest to you

                    1 Reply Last reply
                    1
                    • N Offline
                      N Offline
                      NDev
                      wrote on last edited by
                      #11

                      Is there a way I can find the size/width of the QRadiobutton text and adjust the spacing accordingly?

                      1 Reply Last reply
                      0
                      • ? This user is from outside of this forum
                        ? This user is from outside of this forum
                        Guest
                        wrote on last edited by
                        #12

                        [quote author="NDev" date="1297325032"]Is there a way I can find the size/width of the QRadiobutton text and adjust the spacing accordingly? [/quote]

                        yes: text() is available. Also since a QRadioButton extends a QWidget: font(), fontinfo(), fontmetrics() are all available ..

                        1 Reply Last reply
                        0
                        • N Offline
                          N Offline
                          NDev
                          wrote on last edited by
                          #13

                          Thanks. So how do I calculate the exact width my QRadioButton text is going to take?

                          1 Reply Last reply
                          0
                          • ? This user is from outside of this forum
                            ? This user is from outside of this forum
                            Guest
                            wrote on last edited by
                            #14

                            the documentation should help.. just read through the docs for these QFont, QFontInfo and QFontMetrics .. you will get an idea

                            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