[Qt-interest] check box problem
ramesh.bs at robosoftin.com
ramesh.bs at robosoftin.com
Thu May 13 06:44:43 CEST 2010
Hi Frank and Andre,
Thanks for your answeres..
The behaviour what i expected was, if i click on "radiobutton1",it should
only get ticked and unticked, but in my case if i click on "radiobutton1"
other radio buttons state was getting effected. it because as you said
they are mutually exclusive.. but i found a solution for my problem.
i.e Only I need to set setAutoExclusive properties false to all the radio
button.
Here is the updated code,.
radio1->setAutoExclusive(false);
radio2->setAutoExclusive(false);
radio2->setAutoExclusive(false);
> Hello Ramesh (and Andre) -
>
> On Wed, May 12, 2010 at 7:48 AM, Andre Somers <andre at familiesomers.nl>
> wrote:
>> On 12-5-2010 13:35, Ramesh wrote:
>>
>> Hi, all
>>
>> What is the mistake in this code,
>>
>> Initially, all the check boxes will be selected, later if I click first
>> checkbox, it will get untick, later if I click on the first box again,
>> it
>> will get selected but the second one will be unticked.. similarly if I
>> reaped the process, the third box also get unticked.. my I know where I
>> am
>> wrong
>> ...
>>
>> That is the expected behaviour from radio buttons. You did not specify
>> what
>> kind of behaviour you are looking for, so I have no idea what you want
>> to
>> achieve. Perhaps you should use QCheckBox instead? QRadioButtons are
>> supposed to be mutually exclusive.
>>
>> André
>
> I agree with Andre: It's not clear what behavior you are expecting, so
> I'm not
> sure what you're asking.
>
> As Andre says, if you don't want your buttons to be mutually exclusive,
> use
> something like QCheckBox.
>
> However, I do see in your sample code a reference to "exclusive"...
>
>> Here is the code L
>> ...
>>
>> RadioButtonwidget::RadioButtonwidget(QWidget *parent)
>> : QWidget(parent)
>> {
>>
>> QGroupBox *groupBox = new QGroupBox(tr("Exclusive Radio
>> Buttons"));
>> QRadioButton *radio1 = new QRadioButton(tr("&Radio button 1"));
>> ...
>
> Because you are labelling your QGroupBox "Exclusive Radio Buttons", I will
> assume that you do want radio buttons with their exclusive behavior. (I
> don't,
> however, think your QGroupBox actually gets used in your sample code.)
>
>> ...
>> radio1->setChecked(true);
>> radio2->setChecked(true);
>> radio3->setChecked(true);
>
> This, I think, is your problem.
>
> You set all of your radio buttons to their checked state, violating
> the exclusive
> "invariant". (It's not fully invariant, because it's not fully
> enforced by QRadioButton,
> as your example shows.)
>
> So your RadioButtonwidget displays initially with all of the buttons
> checked, so they
> don't act quite right.
>
> If you want your radio buttons to act normally, you should start out
> with exactly on
> checked, e.g.:
>
> radio1->setChecked(true);
> radio2->setChecked(false);
> radio3->setChecked(false);
>
> Normally you can't uncheck a radio button (that is in a group of more
> than one) by
> clicking on it, but when you start out with more than one checked, you
> can.
> That's the first minor oddity.
>
> Then when re-checking the button you unchecked, rather than clearing all
> of
> the rest of the radio buttons, it appears that Qt (I would guess for the
> sake of
> a minor efficiency gain) unchecks only the the first checked button it
> finds in
> the group of buttons.
>
> So -- as you described -- click the first button twice, and the second
> button
> is unchecked, click the first button twice again, and now the third button
> is
> also unchecked.
>
> Once you get all but one of the radio buttons checked, they should behave
> as expected.
>
> Good luck.
>
> K. Frank
>
>> ...
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
-----------------------------------------------
Robosoft Technologies - Come home to Technology
Disclaimer: This email may contain confidential material. If you were not an intended recipient, please notify the sender and delete all copies. Emails to and from our network may be logged and monitored. This email and its attachments are scanned for virus by our scanners and are believed to be safe. However, no warranty is given that this email is free of malicious content or virus.
More information about the Qt-interest-old
mailing list