如何使用QML工具按钮填充QTableview

如何使用QML工具按钮填充QTableview,qml,qt5,qt-quick,qtquickcontrols,qqmlcomponent,Qml,Qt5,Qt Quick,Qtquickcontrols,Qqmlcomponent,我需要按下红色圆圈下的“创建”按钮,按下该按钮,我试图填充表格视图的第一行。我是QT Quick的新用户,请帮助我。我浪费了很多时间,但没有办法去做 我提供的用户界面和代码,以及请有一个看 谢谢大家! import QtQuick 2.2 import QtQuick.Controls 1.2 import QtQuick.Layouts 1.0 import QtQuick.Dialogs 1.0 import "content" import "images" Applicatio

我需要按下红色圆圈下的“创建”按钮,按下该按钮,我试图填充表格视图的第一行。我是QT Quick的新用户,请帮助我。我浪费了很多时间,但没有办法去做

我提供的用户界面和代码,以及请有一个看

谢谢大家!

    import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.0
import QtQuick.Dialogs 1.0
import "content"
import "images"

ApplicationWindow {
    visible: true
    title: "Mask Editor: Subsystem"

    width: 720
    height: 420
    minimumHeight: 400
    minimumWidth: 720

    statusBar: StatusBar {
        id: minstatusbar

            RowLayout {
                id:row1
              spacing: 2
              width: parent.width
              Button {
                  text:"Unmask"

              }
              Item { Layout.fillWidth: true }
                Button {
                    text:"OK"

                }
                Button {
                    text:"Cancel"

                }
                Button {
                    text:"Help"

                }
                Button {
                    text:"Apply"
                }
            }
        }

  /*  ListModel {
        id: largeModel
        Component.onCompleted: {
            for (var i=0 ; i< 10 ; ++i)
                largeModel.append({"index":i , "prompt": "pmpt", "variable":i+10, "type" : "Female","tabname":"something"})
        }
    }*/


    Action {
        id: openAction
        text: "&Open"
        shortcut: "Ctrl+O"
        iconSource: "images/document-open.png"
        onTriggered: fileDialog.open()
        tooltip: "Open an Image"
    }
    TabView {
        id:frame
        enabled: enabledCheck.checked
        tabPosition: controlPage.item ? controlPage.item.tabPosition : Qt.TopEdge
        anchors.fill: parent
        anchors.margins: Qt.platform.os === "osx" ? 12 : 2

        Tab {
            id: controlPage
            title: "Parameters"
            Item {
                id:root
                anchors.fill: parent
                anchors.margins: 8

                ColumnLayout {
                    id: mainLayout
                    anchors.fill: parent
                    spacing: 4


                    GroupBox {
                        id: gridBox
                        title: "Grid layout"
                        Layout.fillWidth: true
                        ListModel {
                            id: nestedModel
                            ListElement{index:"1";prompt:"pmt";variable:10; type: "to be defined";tabname:"something"}

                        }

                        GridLayout {
                            id: gridLayout
                            anchors.fill: parent
                            rows: 3
                            flow: GridLayout.TopToBottom

                            ToolButton {  iconSource: "images/window-new.png"
                                action:filldata
                                Accessible.name: "New window"
                                onClicked: {

                                 nestedmodel.append({"index":i , "prompt": "pmpt", "variable":i+10, "type" : "Female","tabname":"something"})


                                  }
                                tooltip: "Toggle visibility of the second window" }

                            ToolButton { iconSource: "images/view-refresh.png"
                                onClicked: window1.visible = !window1.visible
                                Accessible.name: "New window"
                                tooltip: "Toggle visibility of the second window" }

                            ToolButton { Accessible.name: "Save as"
                                iconSource: "images/document-save-as@2x.png"
                                tooltip: "(Pretend to) Save as..." }

                            TableView{
                                model: modelcontl
                                Layout.rowSpan: 3
                                Layout.fillHeight: true
                                Layout.fillWidth: true
                                //anchors.fill: parent

                                TableViewColumn {
                                    role: "index"
                                    title: "#"
                                    width: 36
                                    resizable: false
                                    movable: false
                                }
                                TableViewColumn {
                                    role: "prompt"
                                    title: "Prompt"
                                    width: 120
                                }
                                TableViewColumn {
                                    role: "variable"
                                    title: "Variable"
                                    width: 120
                                }
                                TableViewColumn {
                                    role: "type"
                                    title: "Type"
                                    width: 200
                                    visible: true
                                }
                                TableViewColumn {
                                    role: "tabname"
                                    title: "Tab Name"
                                     Layout.fillWidth: true
                                    visible: true
                                }
                            }
                        }
                    }

                    Rectangle{
                        Layout.fillHeight: true
                        Layout.fillWidth: true
                    GridLayout {
                        //id: gridLayout
                                rows: 1
                                flow: GridLayout.TopToBottom
                                anchors.fill: parent
                           GridLayout{
                                      id: grid1
                                      columns: 2
                                      anchors.fill: parent
                                      GroupBox {
                                          //id: gridBox
                                          title: "Grid layout"
                                          Layout.fillHeight: true
                                          Layout.fillWidth: true
                                      }
                                      GroupBox {
                                          //id: gridBox
                                          title: "Grid layout"
                                          Layout.fillHeight: true
                                          Layout.fillWidth: true
                                      }
                                    }

                              }
                          }
              }
            }
        }



        Tab {
            title: "Documentation"
           Controls { }
        }
        Tab {
            title: "dialog"
           MessageDialogs { }
        }


    }

}
导入QtQuick 2.2
导入QtQuick.Controls 1.2
导入QtQuick.Layouts 1.0
导入QtQuick.Dialogs 1.0
导入“内容”
导入“图像”
应用程序窗口{
可见:正确
标题:“掩码编辑器:子系统”
宽度:720
身高:420
最低高度:400
最小宽度:720
状态栏:状态栏{
id:minstatusbar
行布局{
id:第1行
间距:2
宽度:parent.width
钮扣{
文本:“解除伪装”
}
项{Layout.fillWidth:true}
钮扣{
文本:“OK”
}
钮扣{
文本:“取消”
}
钮扣{
文本:“帮助”
}
钮扣{
正文:“应用”
}
}
}
/*列表模型{
id:largeModel
Component.onCompleted:{
对于(变量i=0;i<10;++i)
追加({“index”:i,“prompt”:“pmpt”,“variable”:i+10,“type”:“Female”,“tabname”:“something”})
}
}*/
行动{
id:openAction
文本:“&打开”
快捷方式:“Ctrl+O”
iconSource:“图像/文档打开.png”
OnTiggered:fileDialog.open()文件
工具提示:“打开图像”
}
TabView{
id:框架
已启用:已选中enabledCheck
tabPosition:controlPage.item?controlPage.item.tabPosition:Qt.TopEdge
锚定。填充:父级
anchors.margins:Qt.platform.os==“osx”?12:2
标签{
id:controlPage
标题:“参数”
项目{
id:根
锚定。填充:父级
2.5.8页边距:8
列布局{
id:主布局
锚定。填充:父级
间距:4
分组框{
id:gridBox
标题:“网格布局”
Layout.fillWidth:true
列表模型{
id:nestedModel
ListElement{index:“1”;提示符:“pmt”;变量:10;类型:“待定义”;选项卡名:“something”}
}
网格布局{
id:gridLayout
锚定。填充:父级
行数:3
流程:GridLayout.TopToBottom
工具按钮{iconSource:“images/window new.png”
行动:填充数据
可访问。名称:“新窗口”
再次点击:{
追加({“index”:i,“prompt”:“pmpt”,“variable”:i+10,“type”:“Female”,“tabname”:“something”})
}
工具提示:“切换第二个窗口的可见性”}
工具按钮{iconSource:“图像/视图刷新.png”
onClicked:window1.visible=!window1.visible
可访问。名称:“新窗口”
工具提示:“切换第二个窗口的可见性”}
ToolButton{Accessible.name:“另存为”
iconSource:“图像/文档保存”-as@2x.png"
工具提示:“(假装)另存为…”
桌面视图{
型号:modelcontl
布局。行跨度:3
Layout.fillHeight:true
Layout.fillWidth:true
//锚定。填充:父级
TableViewColumn{
角色:“索引”
标题:“#”
宽度:36
可调整大小:false
可移动:假
}
TableViewColumn{
角色:“提示”
标题:“提示”
宽度:120
}
TableViewColumn{
角色:“变量”
标题:“变量”
宽度:120
}
TableViewColumn{
角色:“类型”
标题:“类型”
宽度:200
可见:正确
}
TableViewColumn{
角色:“tabname”
标题:“选项卡名称”
Layout.fillWidth:true
可见:正确
}
}
}
}
长方形{
Layout.fillHeight:true
Layout.fillWidth:true
网格布局{
//id:gridLayout
行数:1
流程:GridLayout.TopToBottom