QML TableView坑

QML 写界面的时候,把自己坑了,不能正确的选中一行,最后发现第一列用了"index",这个可能是TableView的内置属性(猜测),后边给index赋值,所以不能选中争正确的行,换一个名字即可。



TableView
        {
            x:320;y:0;width: 700;height: 730;
            selectionMode: SelectionMode.SingleSelection;
            TableViewColumn{role: qsTr("index");width: 25;horizontalAlignment: Text.AlignHCenter;}
            TableViewColumn{role: qsTr("name");title: qsTr("名称");width: 100;horizontalAlignment: Text.AlignHCenter;}
            TableViewColumn{role: qsTr("user");title: qsTr("所有者");width: 100;horizontalAlignment: Text.AlignHCenter;}
            TableViewColumn{role: qsTr("createdate");title: qsTr("创建日期");width: 100;horizontalAlignment: Text.AlignHCenter;}
            TableViewColumn{role: qsTr("audit");title: qsTr("全面审计追踪");width: 100;horizontalAlignment: Text.AlignHCenter;
            delegate: Rectangle{anchors.fill: parent;border.color: "#222222";border.width: 1;color: "#d4d0c8";
                CheckBoxCustom{anchors.verticalCenter: parent.verticalCenter;anchors.horizontalCenter: parent.horizontalCenter;text: qsTr("");}}}
            TableViewColumn{role: qsTr("locked");title: qsTr("已锁定");width: 50;horizontalAlignment: Text.AlignHCenter;
                delegate: Rectangle{anchors.fill: parent;border.color: "#222222";border.width: 1;color: "#d4d0c8";
                    CheckBoxCustom{y:-5;anchors.horizontalCenter: parent.horizontalCenter;text: qsTr("");}}}
            TableViewColumn{role: qsTr("note");title: qsTr("注释");width: 100;horizontalAlignment: Text.AlignHCenter;}
            TableViewColumn{role: qsTr("a1");title: qsTr("表空间限额");width: 100;horizontalAlignment: Text.AlignHCenter;}
            TableViewColumn{role: qsTr("a2");title: qsTr("空闲表空间");width: 100;horizontalAlignment: Text.AlignHCenter;}

            headerDelegate: Rectangle
            {
                implicitWidth:100;implicitHeight:25;border.color:"#222222";border.width:1;
                Text
                {
                    verticalAlignment: Text.AlignVCenter;horizontalAlignment: Text.AlignHCenter;
                    text: styleData.value;font.bold: true;anchors.fill:parent;
                }
            }
            rowDelegate: Rectangle
            {
                height:25;color:styleData.selected?"black":"white";
            }
            itemDelegate: Rectangle
            {
                implicitWidth:100;implicitHeight:25;color:"#00a0a0a0";border.color:"#222222";border.width:styleData.selected?0:1;
                Text{x:2;text: styleData.value;verticalAlignment: Text.AlignVCenter;color:styleData.selected?"white":"black";}
            }
            model: ListModel
            {
                ListElement{index:1;name:"Test_1";user:"System";createData:"2018-4-17 17:04:52";}
                ListElement{index:2;name:"Test_1";user:"System";createData:"2018-4-17 17:04:52";}
                ListElement{index:3;name:"Test_1";user:"System";createData:"2018-4-17 17:04:52";}
            }
        }

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭