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

problems about property "enabled" of children widgets vs "enabled" of parent widget

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 4.7.0
    • Tools: Designer
    • None
    • 4.7.0 beta 1, but I saw the same in 4.6.2

    Description

      Bugs/problems (probably closely related):

      • it is not possible to set in designer children property "enabled" to true if parent (e.g. group box) has "enabled" == false
      • changing "enabled" of parent silently changes this property for children, if these children had manually set (i.e. not-default) value of "enabled"
      • you can create a situation where there are differences between what designer shows in property editor and what is really saved in .ui

      Attached bug_example.ui has just standard Qt widgets: one group box and two push buttons within this group box (but the same happens if the children of the group box are e.g. checkboxes or radio buttons etc.). I've also added a checkbox whose signal "toggled(bool)" is connected to groupBox'es slot "setEnabled(bool)", and which can be used in "preview".

      I want to create the following structure:

      • a disabled group box with two child buttons
      • but I want one of the child buttons to have property "enabled" to be true and one to be "false", so that when the parent group box gets enabled it would mean that only one of the children gets enabled.

      This can be achieved by for example keeping groupBox enabled, setting one child button to enabled and one to disabled. For example if you open in designer attached bug_example.ui, select groupBox, set it to enabled==true, select one child button and set it to enabled == true (and keep the other button enabled == false) then in preview you will see that toggling the lower checkbox indeed either sets everything to be disabled (because parent group box is enabled) or enables just one button. Fine this is the behaviour I wanted.

      But this behaviour cannot be set up in designer at all if the parent groupBox is disabled! If you disable the parent groupBox and save the .ui file, then ALL THREE (parent groupBox and both buttons) will have in .ui enabled == false. Now, you can select one of child buttons in designer, go to property editor and double-click on the checkbox representing property "enabled" -> the checkbox will get checked so it will look as if this property is set to "true" but in fact if you save the .ui (or preview the form using Ctrl+R, or select some other widget and come back to this button) you will see that the property is still "false" for this child button!

      This is quite serious I think, it is impossible to set desired behaviour in designer if there are reasons (and there can be many!) to keep the parent groupBox disabled. This will ofc be a big problem for larger forms, where you really want to set as little as possible from the code.

      (Side remark: in some cases you can work around this problem using the fact that if property was not modified manually from its default value, then designer does not save corresponding section in xml at all; but this workaround would not be possible at all for widgets [e.g. custom widgets] which are disabled by default, plus even for regular widgets like in the attached example what is happening is not clear for someone who uses designer).


      Using the same bug_example.ui file you can reproduce a few other weird pieces of behaviour.

      Example 1 (basically mentioned above): load the original attached bug_example.ui, select button2, select property "enabled", set it to "true" (e.g. double-click on the checkbox representing this property), save => in designer's property editor you will see a checked checkbox (so you would expect "enabled==true") but in saved .ui file button2 will have "enabled == false".

      Example 2: load the original bug_example.ui, change groupBox and button 2 to "enabled==true", keep button 1 at "enabled == false". Save as file2.ui. This is fine, this is exactly what you will get in .ui (if you open file2.ui in text editor, you can see that button2 has enabled == true). Fine. Now lets's start anew: close all files. Open file2.ui. Select top-level groupBox, change it's property "enabled" to false, don't change anything about buttons, save. Now look at .ui file => not only the top-level groupBox but also the button2 will now have enabled == false! This is defintely not something I would have expected, and in larger ui files can lead to quite unexpected behaviour.

      In other words: setting parent groupBox'es "enabled" to false from code preserves "enabled" of children. Next time the parent groupBox will get enabled the same children will be enabled as before and the same children will be disabled as before.

      But designer works in a different way: in designer setting parent groupBox'es "enabled" to false sets "enabled" of all children to "false". Not only is this counter-intuitive and can be easily missed but it simply looses information about which child widgets should be enabled next time the groupBox is enabled.


      Just another little scenario using the same ui file, this time looking a bit at how properties which are not set (are kept at default values) are represented.

      1) let's reset all "enabled" properties for the groupBox and 2 buttons to default (test1.ui):

      • in designer all three (groupBox + 2 buttons) "enabled" properties are not-bold (default)
      • and all are checked (enabled == true)
      • in preview enabling is toggled correctly (when one toggles the checkbox in the lower part of the dialog)

      2) now, disable in designer the top-level groupBox, without changing anything for buttons (test2.ui)

      • in designer groupBox'es "enabled" is bold (manually set), buttons' props are not-bold (default)
      • all three are unchecked (enabled == false).
      • This is already BAD: the property "enabled" shows whether the widget will be enabled IF ALL its parents are enabled. The fact that designer shows here enabled == false is misleading! These widgets will become enabled if it's parent will become enabled (example: run the preview and toggle the lower checkbox a few times).
      • It's even worse if you have as children some custom widgets for which you don't remember whether by default they are enabled or disabled => by looking at property editor in designer you simply cannot predict what will happen to these children when later groupBox will become enabled...

      3) but now additionally select the second button and changed it to "enabled" (keeping top groupBox disabled and first button at default value)

      • in designer, those properties "enabled" which are set manually (i.e. for top-group and second checkbox) are bold, the prop of the first button is not-bold (dflt)

      But now the bugs you can see in the situation (3.):
      a) at first, if immediately after toggling the second button "enabled" property to checked, if you change selection in object inspector and go to the other button or the groupBox, you will see FOR ALL THREE "enabled" checked (== "true")! (this is wrong)

      b) But if you save .ui at this moment (test3.ui), you see that what is saved is only properties of top groupBox and the button for which you set not-default value of property "enabled", BUT they will be both "false"! (this is not what you see in property editor - there checkboxes are checked)

      c) If now you select top-level dialog and select again the groupbox or the two buttons in object inspector and look at their "enabled" property in property editor you will see it for all three widgets as unchecked. (Not surprising considering what is in .ui file, but suddenly what you see is different to what you though you had set and to what you saw a second ago!).


      The fact that now designer somehow "propagates" the value of parent's property "enabled" to children:

      • is simply wrong, counter-intuitive and misrepresents what "enabled" means;
      • blocks possibility of setting this property for children of disabled widgets;
      • silently changes this property for children (to false) when you disable the parent while children had already this property set explicitly - by toggling the parent, user can introduce consequences which he/she would not expect...
      • plus there can be differences between what designer shows (as checked checkboxes in property editor) and what is saved (enabled == false).

      Designer should simply in a very plain way allow setting property "enabled" for each widget separately, and the meaning of it should be the same as setting property "enabled" from the code ("enabled == true" should mean that the widget will be enabled IF all its parents are enabled).

      Attachments

        1. test3.ui
          2 kB
          Marek Wieckowski
        2. test2.ui
          2 kB
          Marek Wieckowski
        3. test1.ui
          2 kB
          Marek Wieckowski
        4. bug_example.ui
          2 kB
          Marek Wieckowski

        Issue Links

          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:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes