qml cannot modify the listview header control text

For example, if you set a check box in the header of the Listview, and then want to dynamically modify the text of the check box in other controls, modifying it through the ID is invalid because it is in the header and is undefined for other controls. This can be solved using an external property:

Window {
    
    
    width: 400
    height: 400
    visible: true


    property int title: 1
    property string name: qsTr("1")

    ListView{
    
    
        id: view
        width: parent.width
        height: parent.height - 50
        header: Item{
    
    
            width: parent.width
            height: 30

            CheckBox{
    
    
                id:checkall
                text: name
            }
        }
    }

    Button{
    
    
        width: 60
        height: 20
        anchors.top: view.bottom;
        text: qsTr("切换")
        onClicked: {
    
    
           title += 1
            if(title > 4)
                title = 1
            if(title==1)
                name = qsTr("1")
            else if(title==2)
                name = qsTr("2")
            else if(title==3)
                name = qsTr("3")
            else if(title==4)
                name = qsTr("4")
        }
    }
}

おすすめ

転載: blog.csdn.net/bangtanhui/article/details/133251184