TableModelColumn QML Type

モデルのカラムを表します。詳細...

Import Statement: import Qt.labs.qmlmodels

詳細な説明

TableModelColumn クラスは、TableModel の列を表します。TableModel は JavaScript/JSON データをサポートしており、各行はオブジェクトで、キーが順序付けされていない単純なキーと値のペアのリストです。

{
    // Each property is one cell/column.
    checked: false,
    amount: 1,
    fruitType: "Apple",
    fruitName: "Granny Smith",
    fruitPrice: 1.50
},
// ...

しかし、Qt のモデルは、行と列のインデックスを介して操作されます。TableModelColumnで列を指定することで、Qtの組み込みロールから各行オブジェクトの任意のプロパティへのマッピングが可能になります。

import QtQuick
import QtQuick.Window
import Qt.labs.qmlmodels

Window {
    width: 400
    height: 400
    visible: true

    TableView {
        anchors.fill: parent
        columnSpacing: 1
        rowSpacing: 1
        boundsBehavior: Flickable.StopAtBounds

        model: TableModel {
            TableModelColumn { display: "checked" }
            TableModelColumn { display: "amount" }
            TableModelColumn { display: "fruitType" }
            TableModelColumn { display: "fruitName" }
            TableModelColumn { display: "fruitPrice" }

            // Each row is one type of fruit that can be ordered
            rows: [
                {
                    // Each property is one cell/column.
                    checked: false,
                    amount: 1,
                    fruitType: "Apple",
                    fruitName: "Granny Smith",
                    fruitPrice: 1.50
                },
                {
                    checked: true,
                    amount: 4,
                    fruitType: "Orange",
                    fruitName: "Navel",
                    fruitPrice: 2.50
                },
                {
                    checked: false,
                    amount: 1,
                    fruitType: "Banana",
                    fruitName: "Cavendish",
                    fruitPrice: 3.50
                }
            ]
        }
        delegate:  TextInput {
            text: model.display
            padding: 12
            selectByMouse: true

            onAccepted: model.display = text

            Rectangle {
                anchors.fill: parent
                color: "#efefef"
                z: -1
            }
        }
    }
}

TableModelColumn はまた、複雑な行の基本的な読み取り専用サポートを持っています。詳細はSupported Row Data Structures を参照してください。

注: 上記の概念のほとんどは、TreeModel にも適用されます。ただし、TreeModel では、各行がツリーのノードを表します。

サポートされる役割

TableModelColumn はQt::InitialSortOrderRole を除き、Qt's roles の全てをサポートしています。ロールは以下のようにアクセスすることができます。

text: display

required property string display
Qt::DisplayRole表示
Qt::DecorationRole装飾
Qt::EditRole編集
Qt::ToolTipRoleツールチップ
Qt::StatusTipRoleステータスヒント
Qt::WhatsThisRoleこの内容
Qt::FontRoleフォント
Qt::TextAlignmentRoleテキストアライメント
Qt::BackgroundRole背景
Qt::ForegroundRole前景
Qt::CheckStateRoleチェック状態
Qt::AccessibleTextRoleアクセシブルテキスト
Qt::AccessibleDescriptionRoleアクセス可能な説明
Qt::SizeHintRolesizeHintRoleNam

TableModel および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.