Strange behavior of qtdesktopcomponents Checkbox



  • I'm trying to map checked property of checkbox to something else, in example it's mapped to another checkbox. Everything works eas expected (checked property changes on changing mapping property) until I touch checkbox by mouse. After clicing checkbox it will never react to change of its checked property.

    I need it for represent a bool Q_PROPERTY that can be changed by qml GUI either inside C++ app.

    @import QtQuick 1.1
    import QtDesktop 0.1

    ButtonColumn {
    exclusive: false
    CheckBox {
    id: checkbox1;
    text: "Checkbox 1";
    checked: checkbox2.checked;
    }

      Label {
       text: "checkbox1 checked: " + checkbox1.checked;
      }
      
      CheckBox {
       id: checkbox2;
       text: "Checkbox 2";
       checked: checkbox1.checked;
      }
      
      Label {
       text: "checkbox2 checked: " + checkbox2.checked;
      }
    

    }@


  • Moderators

    I've got no experience in desktop components, but it might well be that when you click on the CB, it sets "checked" to a concrete value, breaking the bond between them (that is, the value changes to, for example, "true", instead of "checkbox2.checked"). Try handling the connection in onCheckedChanged slot - there is should work.



  • Yes this code works
    @import QtQuick 1.1
    import QtDesktop 0.1

    ButtonColumn {
    exclusive: false
    CheckBox {
    id: checkbox1;
    text: "Checkbox 1";
    checked: checkbox2.checked;
    onCheckedChanged: {
    checkbox2.checked = checked;
    checked: checkbox2.checked;
    }
    }

      Label {
       text: "checkbox1 checked: " + checkbox1.checked;
      }
     
      CheckBox {
       id: checkbox2;
       text: "Checkbox 2";
       checked: checkbox1.checked;
       onCheckedChanged: {
    

    checkbox1.checked = checked;
    checked: checkbox1.checked;
    }
    }

      Label {
       text: "checkbox2 checked: " + checkbox2.checked;
      }
    

    }
    @

    But I still have problem with binding property to C++ Q_PROPERTY, it wont work same manner


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.