Details
-
Bug
-
Resolution: Done
-
P4: Low
-
4.6.3
-
None
-
Qt 4.6.3
-
ffe6fcdad9cdcd02e821b59270972a8f04b115a9
Description
In a form created in QtDesigner I have two checkboxes in a Q3ButtonGroup. The problem is in the following situation:
- the first checkbox gets checked from code
- but then when the second checkbox gets checked from code the first one gets unchecked
(as if they were in an exclusive group). I attach an example which reproduces this:
checkBox1->setChecked(true); checkBox2->setChecked(true); qDebug() << "checkBox1 is " << (checkBox1->isChecked() ? "checked" : "UNchecked"); qDebug() << "checkBox2 is " << (checkBox2->isChecked() ? "checked" : "UNchecked");
The result is:
checkBox1 is UNchecked
checkBox2 is checked
The default always has been exclusive == false (and radioButtonExclusive == true). I'm not sure what has changed recently, but basically the old code (using Qt3 forms ported to qt4 with support classes) does not work in this particular case anymore.
Note: but the problem is not in porting - attached example was created from scratch by adding in QtDesigner a Q3ButtonGroup with two checkboxes as children. (My guess is that the problem is probably either in designer or in uic).
Note that if I run setChecked(true) in a delayed way (e.g. single-shot a slot which sets both checkboxes to be checked) then they both do get checked. Also a user can set both checkboxes to be checked by clicking with mouse. It's just that when both checkboxes get checked from the code in the constructor the above happens.
Importance: we have a project with lots of forms used for editing different db records. The initial state is filled in by the code based on db (using Q3SqlForm). At the moment because of above bug independent (not exclusive) boolean fields are restored in a completely wrong way (at most one checkbox is checked).
Additional remarks:
- for buttons in Q3ButtonGroup QtDesigner always sets attribute "buttonGroup"
<attribute name="buttonGroup"> <string/> </attribute>
- during compilation this results in
Warning: Creating button group `'
- in ui_test.h from uic there is:
buttonGroup = new Q3ButtonGroup(Dialog); checkBox1 = new QCheckBox(buttonGroup); checkBox2 = new QCheckBox(buttonGroup);
and both checkboxes are children of this Q3ButtonGroup; but then there is also a Qt4 button group created, to which both checkboxes are added:
QButtonGroup *buttonGroup1 = new QButtonGroup(Dialog); buttonGroup1->addButton(checkBox1); buttonGroup1->addButton(checkBox2);
This is probably what causes the initial "exclusive" behaviour. I'm not sure why later this exclusiveness is gone...
If one removes the section
<attribute name="buttonGroup">
<string/>
</attribute>
from .ui then uic does not create the QButtonGroup (it just creates Q3ButtonGroup) and interface behaves as expected (the two calls "setChecked(true)" set both checkboxes to be checked). But then after opening .ui in designer and saving the form this attribute is back in .ui and the whole incorrect behaviour is back.