このページでは

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::DisplayRoledisplay
Qt::DecorationRole装飾
Qt::EditRoleedit
Qt::ToolTipRoletoolTip
Qt::StatusTipRolestatusTip
Qt::WhatsThisRolewhatsThis
Qt::FontRoleフォント
Qt::TextAlignmentRoletextAlignment
Qt::BackgroundRolebackground
Qt::ForegroundRole前景色
Qt::CheckStateRolecheckState
Qt::AccessibleTextRoleアクセシブルテキスト
Qt::AccessibleDescriptionRoleアクセシブルな説明
Qt::SizeHintRoleサイズヒント役割名

TableModel およびTableViewも参照してください 。

© 2026 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.