Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-11431

checkboxes in Q3ButtonGroup are initially exclusive

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P4: Low
    • 4.7.0
    • 4.6.3
    • Tools: Designer
    • 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.

      Attachments

        1. 100615-exclusive.tar.bz2
          1 kB
        2. qtbug11431_2.patch
          2 kB
        3. qtbug11431.patch
          2 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kleint Friedemann Kleint
            wiecko Marek Wieckowski
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes