Results 1 to 10 of 10

Thread: Non editable Radio Buttons

  1. #1
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Non editable Radio Buttons

    Hi,
    How to make a QRadioButton non-editable and also it should be enabled and checkable(using setChecked() in the program).
    Last edited by babu198649; 11th November 2009 at 08:01.

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Non editable Radio Buttons

    Quote Originally Posted by babu198649 View Post
    Hi,
    How to make a QRadioButton non-editable and also it should be enabled and checkable(using setChecked() in the program).
    Check it manually and simply disable it
    Qt Code:
    1. rb2.setChecked(true);
    2. rb2.setEnabled(false);
    To copy to clipboard, switch view to plain text mode 

    And play with QPalette if you want the disbled button look like enabled.

  3. #3
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: Non editable Radio Buttons

    It should be both checkable and enabled (but the user should not be able to check or uncheck it)

  4. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Non editable Radio Buttons

    Quote Originally Posted by babu198649 View Post
    It should be both checkable and enabled (but the user should not be able to check or uncheck it)
    Your sentance is contradictory.
    If its checkable then it means user can also change its state.
    I still suggest the same way.
    1. Disable it.(Now user cant change the state but internally you can, by calling setChecked(true))
    2. Change its palette/style/stylesheet so it will look like enabled one.

  5. #5
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: Non editable Radio Buttons

    Thats it my requirement. The QRadioButton should be enable but the user should not be able to edit it. Whereas it can be ediited in the program.

  6. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Non editable Radio Buttons

    That would be against every ui guideline in existance, but hey, it's your project.

    yogeshgokul has already given you an answer (which is also the easiest). Another would be to just leave it enabled and eat all mouse events by subclassing the control or installing an event filter.

  7. #7
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Non editable Radio Buttons

    Quote Originally Posted by fatjuicymole View Post
    Another would be to just leave it enabled and eat all mouse events by subclassing the control or installing an event filter.
    I also thoght that way, but a radio button can be checked using keyboard . Using space bar.

  8. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Non editable Radio Buttons

    Something like that should work and is rather simple:
    Qt Code:
    1. class MyRadioButton : public QRadiobutton
    2. {
    3. //...
    4. void setChecked(bool) {}
    5. void setCheckedByMyProgramm(bool b) {QRadiobutton::setChecked(b);}
    6. void toggle() {}
    7. };
    To copy to clipboard, switch view to plain text mode 
    Last edited by Lykurg; 11th November 2009 at 11:07. Reason: updated contents

  9. The following user says thank you to Lykurg for this useful post:

    babu198649 (11th November 2009)

  10. #9
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: Non editable Radio Buttons

    I also thoght that way, but a radio button can be checked using keyboard . Using space bar.
    By Installing an event filter on an object we can filter the keyboard events also.

  11. #10
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Non editable Radio Buttons

    Quote Originally Posted by babu198649 View Post
    By Installing an event filter on an object we can filter the keyboard events also.
    Ohh, Thanx.

Similar Threads

  1. Replies: 2
    Last Post: 11th August 2009, 16:01
  2. Radio buttons in a tree view
    By notwithstanding in forum Qt Programming
    Replies: 6
    Last Post: 3rd November 2008, 22:32
  3. Programatically setting radio buttons
    By Doug Broadwell in forum Newbie
    Replies: 2
    Last Post: 25th May 2007, 20:55
  4. array of radio buttons
    By amulya in forum Qt Programming
    Replies: 4
    Last Post: 5th October 2006, 12:59
  5. How to get larger radio buttons on XP?
    By Ben.Hines in forum Qt Programming
    Replies: 9
    Last Post: 24th April 2006, 19:00

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
  •  
Qt is a trademark of The Qt Company.