Results 1 to 5 of 5

Thread: Mutual position of the QRadioButton Indicator and text

  1. #1
    Join Date
    Sep 2010
    Posts
    62
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Mutual position of the QRadioButton Indicator and text

    Hello,

    Is it possible to style the QRadioButton (and maybe als the QCheckBox) so that the text can be on the left sight of the Indicator, or above it?

    Thx for your help.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Mutual position of the QRadioButton Indicator and text

    Yes, it is possible. One way which I could suggest right way is use QStyleSheet with somthing like this

    Qt Code:
    1. setStyleSheet(QString::fromUtf8("QCheckBox {\n"
    2. " width: 10px;\n"
    3. " spacing: -75px;\n"
    4. "}\n"
    5. "\n"
    6. "QCheckBox::indicator {\n"
    7. " subcontrol-origin: content;\n"
    8. " subcontrol-position: right top;\n"
    9. "}"));
    To copy to clipboard, switch view to plain text mode 

    " width: 10px;\n" - is required
    " spacing: -75px;\n" - does the magic, and "-75" should be dynamically calculated based on your text rending length on screen, (may you build this into the custom QCheckBox class)

  3. #3
    Join Date
    Sep 2010
    Posts
    62
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Mutual position of the QRadioButton Indicator and text

    Thank you for the answer,

    Unfortunately this does not work in my configuration (Qt 4.6 and SUSE 10.3).
    The first issue - negative spacing shows the truncated text directly ON CheckBox (does no matter how many negative px is set), by the second issue the text disappears completely.
    Maybe in the newer versions this will work correctly.


    Added after 10 minutes:


    p.s.
    I hate these style sheets!
    That's mixing of C++ with "something"!
    Why there is no simply an according method for such operations?
    Last edited by lotek; 16th June 2011 at 20:50.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Mutual position of the QRadioButton Indicator and text

    Subclass QRadioButton, draw the indicator using QStyle, then draw the text where you need it using QPainter::drawText().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    May 2015
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Mutual position of the QRadioButton Indicator and text

    If you want the text on the left side and the icon on the right, you should be able to use:

    radioButton->setLayoutDirection(Qt::RightToLeft);

Similar Threads

  1. change text color on QRadioButton
    By vonCZ in forum Newbie
    Replies: 4
    Last Post: 7th November 2012, 20:05
  2. Replies: 1
    Last Post: 12th April 2010, 10:44
  3. Button Text Position
    By Slewman in forum Qt Tools
    Replies: 1
    Last Post: 29th September 2009, 16:35
  4. mutual authentication
    By abeinoe in forum Qt Programming
    Replies: 2
    Last Post: 6th April 2009, 06:22
  5. Position of text in a qlabel
    By jiveaxe in forum Qt Programming
    Replies: 1
    Last Post: 25th May 2008, 13:26

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.