QStringListModel 类

QStringListModel class provides a model that supplies strings to views. 更多...

头: #include <QStringListModel>
qmake: QT += core
继承: QAbstractListModel
继承者:

QHelpIndexModel

公共函数

QStringListModel (QObject * parent = Q_NULLPTR)
QStringListModel (const QStringList & strings , QObject * parent = Q_NULLPTR)
void setStringList (const QStringList & strings )
QStringList stringList () const

重实现公共函数

virtual QVariant data (const QModelIndex & index , int role = Qt::DisplayRole) const
virtual Qt::ItemFlags flags (const QModelIndex & index ) const
virtual bool insertRows (int row , int count , const QModelIndex & parent = QModelIndex())
virtual bool removeRows (int row , int count , const QModelIndex & parent = QModelIndex())
virtual int rowCount (const QModelIndex & parent = QModelIndex()) const
virtual bool setData (const QModelIndex & index , const QVariant & value , int role = Qt::EditRole)
virtual QModelIndex sibling (int row , int column , const QModelIndex & idx ) const
virtual void sort (int column , Qt::SortOrder order = Qt::AscendingOrder)
virtual Qt::DropActions supportedDropActions () const

额外继承成员

详细描述

QStringListModel class provides a model that supplies strings to views.

QStringListModel is an editable model that can be used for simple cases where you need to display a number of strings in a view widget, such as a QListView QComboBox .

模型提供可编辑模型的所有标准功能,将字符串列表中的数据表示成具有一列和行数等于列表项数的模型。

对应项的模型索引的获得采用 index() function, and item flags are obtained with flags ()。项数据的读取采用 data () 函数和写入采用 setData ()。行数 (和字符串列表中的项数) 可以找到采用 rowCount () 函数。

模型可以采用现有字符串列表构建,或稍后可以设置字符串采用 setStringList () 方便函数。也可以按通常方式插入字符串采用 insertRows () 函数,和移除采用 removeRows ()。可以检索字符串列表的内容采用 stringList () 方便函数。

An example usage of QStringListModel :

    QStringListModel *model = new QStringListModel();
    QStringList list;
    list << "a" << "b" << "c";
    model->setStringList(list);
					

另请参阅 QAbstractListModel , QAbstractItemModel ,和 模型类 .

成员函数文档编制

QStringListModel:: QStringListModel ( QObject * parent = Q_NULLPTR)

构造字符串列表模型采用给定 parent .

QStringListModel:: QStringListModel (const QStringList & strings , QObject * parent = Q_NULLPTR)

构造的字符串列表模型包含指定 strings 采用给定 parent .

[virtual] QVariant QStringListModel:: data (const QModelIndex & index , int role = Qt::DisplayRole) const

重实现自 QAbstractItemModel::data ().

返回数据为指定 role ,从项采用给定 index .

若视图请求无效索引,则返回无效变体。

另请参阅 setData ().

[virtual] Qt::ItemFlags QStringListModel:: flags (const QModelIndex & index ) const

重实现自 QAbstractItemModel::flags ().

Returns the flags for the item with the given index .

Valid items are enabled, selectable, editable, drag enabled and drop enabled.

另请参阅 QAbstractItemModel::flags ().

[virtual] bool QStringListModel:: insertRows ( int row , int count , const QModelIndex & parent = QModelIndex())

重实现自 QAbstractItemModel::insertRows ().

插入 count rows into the model, beginning at the given row .

parent index of the rows is optional and is only used for consistency with QAbstractItemModel . By default, a null index is specified, indicating that the rows are inserted in the top level of the model.

另请参阅 QAbstractItemModel::insertRows ().

[virtual] bool QStringListModel:: removeRows ( int row , int count , const QModelIndex & parent = QModelIndex())

重实现自 QAbstractItemModel::removeRows ().

移除 count rows from the model, beginning at the given row .

parent index of the rows is optional and is only used for consistency with QAbstractItemModel . By default, a null index is specified, indicating that the rows are removed in the top level of the model.

另请参阅 QAbstractItemModel::removeRows ().

[virtual] int QStringListModel:: rowCount (const QModelIndex & parent = QModelIndex()) const

重实现自 QAbstractItemModel::rowCount ().

Returns the number of rows in the model. This value corresponds to the number of items in the model's internal string list.

可选 parent argument is in most models used to specify the parent of the rows to be counted. Because this is a list if a valid parent is specified, the result will always be 0.

另请参阅 insertRows (), removeRows (),和 QAbstractItemModel::rowCount ().

[virtual] bool QStringListModel:: setData (const QModelIndex & index , const QVariant & value , int role = Qt::EditRole)

重实现自 QAbstractItemModel::setData ().

设置数据按指定 role 在项采用给定 index 在模型,以提供 value .

dataChanged () signal is emitted if the item is changed.

另请参阅 Qt::ItemDataRole and data ().

void QStringListModel:: setStringList (const QStringList & strings )

将模型的内部字符串列表设为 strings 。模型将通知任何附加视图其底层数据已改变。

另请参阅 stringList () 和 dataChanged ().

[virtual] QModelIndex QStringListModel:: sibling ( int row , int column , const QModelIndex & idx ) const

重实现自 QAbstractItemModel::sibling ().

[virtual] void QStringListModel:: sort ( int column , Qt::SortOrder order = Qt::AscendingOrder)

重实现自 QAbstractItemModel::sort ().

QStringList QStringListModel:: stringList () const

返回模型用于存储数据的字符串列表。

另请参阅 setStringList ().

[virtual] Qt::DropActions QStringListModel:: supportedDropActions () const

重实现自 QAbstractItemModel::supportedDropActions ().