QGenericItemModel::MultiColumn Struct

template <typename T> struct QGenericItemModel::MultiColumn

Represents the wrapped type T as multiple columns in a QGenericItemModel. More...

This struct was introduced in Qt 6.10.

Detailed Description

Use this type to disambiguate when the type T has both a metaobject, and implements the C++ tuple protocol. The type will be represented as multiple columns, and the individual values will be accessed through the tuple protocol.

class ColorEntry
{
    Q_GADGET
    Q_PROPERTY(QString display MEMBER m_colorName)
    Q_PROPERTY(QColor decoration READ decoration)
    Q_PROPERTY(QString toolTip READ toolTip)
public:
    ColorEntry(const QString &color = {})
        : m_colorName(color)
    {}

    QColor decoration() const
    {
        return QColor::fromString(m_colorName);
    }
    QString toolTip() const
    {
        return QColor::fromString(m_colorName).name();
    }

private:
    QString m_colorName;
};
namespace std {
    template <> struct tuple_size<ColorEntry> : integral_constant<size_t, 3> {};
    // ...
}

QList<QGenericItemModel::MultiColumn<ColorEntry>> colors = {
    // ...
};
QGenericItemModel colorList(colors);

To represent the type a single column value with multiple roles, use QGenericItemModel::SingleColumn instead.

See also QGenericItemModel::SingleColumn.

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