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.