Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. CheckBox in TableView, Get the checked status

CheckBox in TableView, Get the checked status

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 2.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    levinie
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved