이 페이지에서

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::DecorationRoledecoration
Qt::EditRoleedit
Qt::ToolTipRoletoolTip
Qt::StatusTipRolestatusTip
Qt::WhatsThisRolewhatsThis
Qt::FontRole글꼴
Qt::TextAlignmentRoletextAlignment
Qt::BackgroundRolebackground
Qt::ForegroundRole전경
Qt::CheckStateRole선택 상태
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.