TableModelColumn QML Type | Qt 6.11
Description: Represents a column in a model.

- Qt 6.11
- QML Types
- Qt.labs.qmlmodels
- TableModelColumn
- Qt 6.11.2 Reference Documentation

# TableModelColumn QML Type

Represents a column in a model. More...

Import Statement: | `import Qt.labs.qmlmodels`

- List of all members, including inherited members

## Detailed Description

The TableModelColumn class represents columns in TableModel. TableModel supports JavaScript/JSON data where each row is an object, a list of simple key-value pairs where the keys are unordered.

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

However, models in Qt are manipulated via row and column indices. Specifying the columns with TableModelColumn allows a mapping between Qt's built-in roles to any property in each row object.

     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 also has basic read-only support for complex rows. For more information, see Supported Row Data Structures.

Note: Most of the above concepts also apply to TreeModel, except in TreeModel each row represents a node of the tree.

## Supported Roles

TableModelColumn supports all of Qt's roles, with the exception of `Qt::InitialSortOrderRole`. Roles can be accessed by as listed below, e.g.

     text: display

     required property string display

Qt::DisplayRole | display
Qt::DecorationRole | decoration
Qt::EditRole | edit
Qt::ToolTipRole | toolTip
Qt::StatusTipRole | statusTip
Qt::WhatsThisRole | whatsThis
Qt::FontRole | font
Qt::TextAlignmentRole | textAlignment
Qt::BackgroundRole | background
Qt::ForegroundRole | foreground
Qt::CheckStateRole | checkState
Qt::AccessibleTextRole | accessibleText
Qt::AccessibleDescriptionRole | accessibleDescription
Qt::SizeHintRole | sizeHintRoleNam

See also TableModel and TableView.