PDA

View Full Version : Non editable Radio Buttons



babu198649
11th November 2009, 07:51
Hi,
How to make a QRadioButton non-editable and also it should be enabled and checkable(using setChecked() in the program).

yogeshgokul
11th November 2009, 09:28
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 ;)

QRadioButton rb1;
QRadioButton rb2;
rb2.setChecked(true);
rb2.setEnabled(false);

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

babu198649
11th November 2009, 09:32
It should be both checkable and enabled (but the user should not be able to check or uncheck it)

yogeshgokul
11th November 2009, 09:40
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.

babu198649
11th November 2009, 09:50
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.

squidge
11th November 2009, 10:32
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.

yogeshgokul
11th November 2009, 10:43
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.

Lykurg
11th November 2009, 11:06
Something like that should work and is rather simple:

class MyRadioButton : public QRadiobutton
{
//...
void setChecked(bool) {}
void setCheckedByMyProgramm(bool b) {QRadiobutton::setChecked(b);}
void toggle() {}
};

babu198649
11th November 2009, 11:36
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.

yogeshgokul
11th November 2009, 11:48
By Installing an event filter on an object we can filter the keyboard events also.
Ohh, Thanx. :D