In questa pagina

TableModelColumn QML Type

Rappresenta una colonna in un modello. Maggiori informazioni...

Import Statement: import Qt.labs.qmlmodels

Descrizione dettagliata

La classe TableModelColumn rappresenta le colonne in TableModel. TableModel supporta dati JavaScript/JSON in cui ogni riga è un oggetto, ovvero un elenco di semplici coppie chiave-valore in cui le chiavi non sono ordinate.

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

Tuttavia, i modelli in Qt vengono gestiti tramite indici di riga e colonna. Specificare le colonne con TableModelColumn consente una mappatura tra i ruoli integrati di Qt e qualsiasi proprietà in ciascun oggetto riga.

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 offre inoltre un supporto di base in sola lettura per le righe complesse. Per ulteriori informazioni, consultare Supported Row Data Structures.

Nota: la maggior parte dei concetti sopra descritti si applica anche a TreeModel, tranne per il fatto che in TreeModel ogni riga rappresenta un nodo dell’albero.

Ruoli supportati

TableModelColumn supporta tutti i ruoli di Qt's roles, ad eccezione di Qt::InitialSortOrderRole. È possibile accedere ai ruoli come indicato di seguito, ad esempio

text: display

required property string display
Qt::DisplayRoledisplay
Qt::DecorationRoledecoration
Qt::EditRoleedit
Qt::ToolTipRoletoolTip
Qt::StatusTipRolestatusTip
Qt::WhatsThisRolecos'è
Qt::FontRolefont
Qt::TextAlignmentRoleallineamento testo
Qt::BackgroundRolesfondo
Qt::ForegroundRoleprimo piano
Qt::CheckStateRolestato-selezione
Qt::AccessibleTextRoletesto accessibile
Qt::AccessibleDescriptionRoledescrizione accessibile
Qt::SizeHintRoledimensioniSuggerimentoNomeRuolo

Vedi anche TableModel e 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.