qml 无法修改listview表头控件文本

比如在Listview的表头设置了一个复选框,之后想要在其他控件中动态修改复选框的文本,通过id来修改无效,因为它在表头内,对其他控件来说未定义。可以采用一个外部属性来解决:

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
QML