QStringListModel 類

The 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

額外繼承成員

詳細描述

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

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

重實現自 QAbstractItemModel::data ().

返迴數據為指定 role ,從項采用給定 index .

若視圖請求無效索引,則返迴無效變體。

另請參閱 setData ().

[虛擬] 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 ().

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

重實現自 QAbstractItemModel::insertRows ().

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

The 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 ().

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

重實現自 QAbstractItemModel::removeRows ().

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

The 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 ().

[虛擬] 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 ().

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

重實現自 QAbstractItemModel::setData ().

設置數據按指定 role 在項采用給定 index 在模型,以提供 value .

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

另請參閱 Qt::ItemDataRole and data ().

void QStringListModel:: setStringList (const QStringList & strings )

將模型的內部字符串列錶設為 strings 。模型將通知任何附加視圖其底層數據已改變。

另請參閱 stringList () 和 dataChanged ().

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

重實現自 QAbstractItemModel::sibling ().

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

重實現自 QAbstractItemModel::sort ().

QStringList QStringListModel:: stringList () const

返迴模型用於存儲數據的字符串列錶。

另請參閱 setStringList ().

[虛擬] Qt::DropActions QStringListModel:: supportedDropActions () const

重實現自 QAbstractItemModel::supportedDropActions ().