CheckBox in TableView, Get the checked status



  • OK, I'm a new guy to Qt & qml, and qml really cool.
    Now i want add checkbox in special items of the table.
    But how can i get the property checked?

    Here is my Code:

    @
    Rectangle{
    Component {
    id: checkbox_rwd
    Item {
    id: item_ok
    property string chck: "N"
    CheckBox {
    id: checkbox_ok
    MouseArea {
    id: mousearea_ok
    anchors.fill: parent
    onClicked: {
    if (checkbox_ok.checked){
    checkbox_ok.checked = false;
    }
    else{
    checkbox_ok.checked = true;
    }
    }
    }
    }
    }
    }

        ListModel {
            id: model_node
            //            ListElement{ ip: "255.255.255.255" ; path: "/root/filetest"; w: ""; r: ""; rw: ""; wd: ""; }
            //            ListElement{ ip: "255.255.255.255" ; path: "/root/filetest"; w: ""; r: ""; rw: ""; wd: ""; }
        }
    
        TableView {
            id: table_node
            x: 29
            y: 93
            width: 500
            height: 150
            TableViewColumn{ role: "select"; title:""; width: 15; delegate: checkbox_rwd; }
            TableViewColumn{ role: "ip"  ; title: "IP" ; width: 120;  }
            TableViewColumn{ role: "path" ; title: "path" ; width: 150;  }
            TableViewColumn{ role: "w"  ; title: "write" ; width: 30; delegate: checkbox_rwd }
            TableViewColumn{ role: "r"  ; title: "read" ; width: 30; delegate: checkbox_rwd }
            TableViewColumn{ role: "rw"  ; title: "rw" ; width: 40; delegate: checkbox_rwd }
            TableViewColumn{ role: "wd"  ; title: "rd" ; width: 40; delegate: checkbox_rwd }
            TableViewColumn{ role: "enabled"  ; title: "enabled" ; width: 40; delegate: checkbox_rwd }
            model: model_node
        }
    

    }

    function add_node(){
        //get input
        var ip = textinput_ip.text;
        var path = textinput_path.text;
        //add
        if (ip && path){
            var new_item = {"ip":ip, "path":path, "w": "N", "r": "N", "rw": "N", "wd": "N", "enabled":"N" }; //N means NO
            model_node.append(new_item);
        }
    }
    
    function get_checked(){
        var row_count = model_node.count;
        var info = {};
        for (var i=0; i<row_count; i++){
            var tmp_dict = {};
            var item = model_node.get(i)
            var ip = item.ip;
            var path = item.path;
            tmp_dict.ip = ip;
            tmp_dict.dir = dir;
            info[i] = tmp_dict;
        }
        info = JSON.stringify(info);
        return info;
    }
    

    @

    OK, I get the ip and path with ListModel.get(index), not w, r, rw, wd (these items contain checkbox, i need the checked value).
    how can i get these checked status?


Log in to reply
 

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