TableViewDelegate QML Type

TableView に割り当てることができるデリゲート

Import Statement: import QtQuick.Controls
Since: Qt 6.9
Inherits:

ItemDelegate

プロパティ

詳細説明

TableViewDelegate は、TableViewdelegate property に割り当てることができるデリゲートです。 アプリケーションのスタイルを使用して、ビュー内のテーブルの各セルをレンダリングします。

TableView {
    anchors.fill: parent
    delegate: TableViewDelegate {}
    // model: yourModel
}

TableViewDelegate はItemDelegate を継承しており、backgroundcontentItem の2つのアイテムから構成されています。

contentItem の位置はpadding で制御します。

ポインタとの対話

TableViewDelegate はItemDelegate を継承しています。つまり、ユーザーがデリゲートをクリックすると、clicked のようなシグナルを発します。このシグナルに接続して、アプリケーション固有の機能を実装することができます。

しかし、ItemDelegate APIは、クリックの位置や、どの修飾子が保持されているかについての情報を与えてくれません。このような情報が必要な場合は、ポインタ・ハンドラなどを使うのがよいでしょう:

TableView {
    id: tableView
    delegate: TableViewDelegate {
        TapHandler {
            acceptedButtons: Qt.RightButton
            onTapped: someContextMenu.open()
        }

        TapHandler {
            acceptedModifiers: Qt.ControlModifier
            onTapped: tableView.doSomethingToCell(row, column)
        }
    }
}

注: ユーザーがデリゲートをクリックしたときに発生するデフォルトの動作(現在のインデックスの変更など)を無効にしたい場合は、pointerNavigationEnabledfalse に設定します。

テーブルのセルの編集

TableViewDelegate にはデフォルトでedit delegate が割り当てられています。TableViewedit triggers が設定され、modelediting model items のサポートがある場合、ユーザーは編集トリガーのいずれかをアクティブにして、current テーブルセルのテキストを編集することができます。

デフォルトのeditデリゲートはQt.EditRole を使用して、model にデータを読み書きします。別のロールを使用する必要がある場合、またはデフォルトのeditデリゲートが提供する以外のニーズがある場合は、いつでも独自のデリゲートをTableView.editDelegate に割り当てることができます。

TableViewDelegate のカスタマイズと TableViewも参照してください

プロパティの説明

current : bool

このプロパティは、デリゲートがselection modelcurrent index を表しているかどうかを保持します。


editing : bool

このプロパティは、デリゲートがedited を表しているかどうかを保持します。


selected : bool

このプロパティは、デリゲートがselection modelselected index を表しているかどうかを保持します。


tableView : TableView

このプロパティは、デリゲート項目を含むTableView を指す。


© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.