diff options
| author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2022-11-18 12:37:56 +0100 |
|---|---|---|
| committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2022-12-01 12:01:46 +0100 |
| commit | ed83f0f795132ef20ee6fafbad911a3da0a6c481 (patch) | |
| tree | 8b6301a2001f2aa5e723a282c9915d582a80fcb8 /src/quick/doc/snippets | |
| parent | 97f348f6b9345bb3592bc32553101c8f7f4e1202 (diff) | |
QQuickTableView: implement TableView.editDelegate
This patch will implement support for editing cells
in TableView. It enables you to attach an edit delegate
to the tableview delegate, using the attached property
TableView.editDelegate.
The application can initiate editing by calling TableView.edit()
(and TableView.closeEditor()) explicitly, or implicitly by using
edit triggers. The EditTriggers enum in TableView mirrors the
EditTriggers in QTableView (Widgets).
[ChangeLog][Quick][TableView] Added support for editing cells
Fixes: QTBUG-108838
Change-Id: I25df93a7eeabf9d8a4c4c6248e020d8eba6d5bd7
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quick/doc/snippets')
| -rw-r--r-- | src/quick/doc/snippets/qml/tableview/editdelegate.qml | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/quick/doc/snippets/qml/tableview/editdelegate.qml b/src/quick/doc/snippets/qml/tableview/editdelegate.qml new file mode 100644 index 0000000000..1fdf9e7b3a --- /dev/null +++ b/src/quick/doc/snippets/qml/tableview/editdelegate.qml @@ -0,0 +1,52 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQuick +import QtQuick.Window +import QtQuick.Controls +import QtQml.Models +import Qt.labs.qmlmodels + +Window { + width: 480 + height: 640 + visible: true + visibility: Window.AutomaticVisibility + +//![0] + TableView { + id: tableView + anchors.fill: parent + clip: true + + model: TableModel { + TableModelColumn { display: "name" } + rows: [ { "name": "Harry" }, { "name": "Hedwig" } ] + } + + selectionModel: ItemSelectionModel {} + + delegate: Rectangle { + implicitWidth: 100 + implicitHeight: 50 + + Text { + anchors.centerIn: parent + text: display + } + + TableView.editDelegate: TextField { + text: display + horizontalAlignment: TextInput.AlignHCenter + verticalAlignment: TextInput.AlignVCenter + Component.onCompleted: selectAll() + + TableView.onCommit: { + let index = TableView.view.modelIndex(column, row) + TableView.view.model.setData(index, text, Qt.DisplayRole) + } + } + } + } +//![0] +} |
