Home > front end >  Updating property binding
Updating property binding

Time:12-30

This code breaks the binding once the image is clicked. view.visible logic (conditions) will not work after that. It will continue to remain true. How can I change the view visibility? I think it makes sense to add conditions to visible property visible: (model.count > 0) ? true : false but I'm not sure how to write the ternary operator to achieve this.

  Text {
        id: text1
        visible: !view.visible
        text: qsTr("No tests results")
    }

   Image {
        id: img
        visible: !view.visible
        MouseArea {
            anchors.fill: parent
            onClicked: {
                view.visible = true
                console.log("Clicked")
            }
        }
    }

    ListView {
            id: view
            anchors.fill: parent
            visible: (model !== null) && (model.count > 0) ? true : false
     }

CodePudding user response:

You could simply add another property and bind that in your conditional. For example:

    Text {
        id: text1
        visible: !view.visible
        text: qsTr("No tests results")
    }

    Image {
        id: img
        visible: !view.visible
        property bool showStuff: true
        MouseArea {
            anchors.fill: parent
            onClicked: {
                showStuff = false
                console.log("Clicked")
            }
        }
    }

    ListView {
            id: view
            anchors.fill: parent
            visible: (model.count > 0 && img.showStuff)
     }

The binding for view's visibility will be maintained.

  • Related