Hi,
How to make a QRadioButton non-editable and also it should be enabled and checkable(using setChecked() in the program).
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.
Check it manually and simply disable it
Qt Code:
QRadioButton rb1; QRadioButton rb2; rb2.setChecked(true); 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.
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.
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.
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.
Something like that should work and is rather simple:
Qt Code:
class MyRadioButton : public QRadiobutton { //... void setChecked(bool) {} void setCheckedByMyProgramm(bool b) {QRadiobutton::setChecked(b);} void toggle() {} };To copy to clipboard, switch view to plain text mode
Last edited by Lykurg; 11th November 2009 at 11:07. Reason: updated contents
babu198649 (11th November 2009)
By Installing an event filter on an object we can filter the keyboard events also.I also thoght that way, but a radio button can be checked using keyboard . Using space bar.
Bookmarks