import QtQuick 2.12 import QtQuick.Controls 1.4 import QtQuick.Controls 2.15 import QtQuick.Layouts 1.2 import QtQuick.Window 2.15 Window { id: window width: 640 height: 480 visible: true title: qsTr("Hello TableView") Item{ Rectangle{ id:rect objectName : "Rect" width: parent.width; height: parent.height ListModel { id: sourceModel } Component { id: columnComponent TableViewColumn{ width: 100; resizable :true movable:false } } TableView { id: tableView model: sourceModel x:parent.x y:parent.y width: parent.width height: parent.height horizontalScrollBarPolicy : Qt.ScrollBarAsNeeded verticalScrollBarPolicy : Qt.ScrollBarAsNeeded backgroundVisible : false headerDelegate: Rectangle { Text { text: styleData.value } } rowDelegate: Rectangle { color: "#ffffff" } itemDelegate: Rectangle { Text { text: styleData.value } } } } function addTableColumn(title,role, width) { var column = tableView.addColumn(columnComponent); column.title = title; column.role = role; column.width = width; } function appendTableRow(item1,item2,item3,item4) { var element = sourceModel.append({"item1" : item1, "item2" : item2, "item3" : item3, "item4" : item4}); } } }