Edit TableView Content from other QML File
-
Hello guys,
I want to add content to Tableview from an other QML File. I have no idea, how to do this.
Here are my two Files:MarkerView File:
import QtQuick 2.12 import QtQuick.Controls 2.12 import QtQuick.Layouts 1.12 import QtQuick.Window 2.2 import Qt.labs.qmlmodels 1.0 Window{ width: 500 height: 500 title: "Markierungen" property var horizontal_header_data: ["ID", "Name", "Zeitpunkt"] property TableView markerTable : TableView{ id: markerTable anchors.fill: parent boundsBehavior: Flickable.StopAtBounds topMargin: horizontalHeader.height clip: true // clip content to table dimensions columnSpacing: 1 // in case of big/row spacing, you need to take care of width/height providers (to get along with it) property var columnWidths: [50, 100, 100] columnWidthProvider: function(column){ return columnWidths[column] } Row { id: horizontalHeader y: markerTable.contentY z: 2 Repeater { model: markerTable.columns Label { width: markerTable.columnWidthProvider(modelData); height: 30 text: horizontal_header_data[index] padding: 12 verticalAlignment: Text.AlignVCenter; horizontalAlignment: Text.AlignHCenter color: "white" background: Rectangle { color: "#b5b5b5" } } } } model: TableModel{ TableModelColumn{ display: "ID" id: idColumn } TableModelColumn{ display: "Name" id: nameColumn } TableModelColumn{ display: "Zeitpunkt" id: zeitpunktColumn } } delegate: DelegateChooser{ DelegateChoice{ column: 0 delegate: Label{ padding: 12 text: model.display } } DelegateChoice{ column: 1 delegate: TextField{ placeholderText: "Name" selectByMouse: true padding: 12 onAccepted: model.display = text } } DelegateChoice{ column: 2 delegate: Label{ text: model.display padding: 12 MouseArea{ anchors.fill: parent onPressed: { // slider.value = controller.stepForTime(model.display); // controller.setStep(slider.value); } } } } } } }
Want to add content to the table, when i press on a MenuItem in an other File:
Menu{ id: contextMenu MenuItem{ text: "Marker Position" onTriggered:{ markerTable.model.appendRow({ID: markerTable.model.rowCount+1 + "",Name:"", Zeitpunkt: "" + Qt.formatDateTime(controller.timeForStep(slider.value),timeFormat),}) } } }