The QStringListModel class provides a model that supplies strings to views. 更多...
头: | #include <QStringListModel> |
qmake: | QT += core |
继承: | QAbstractListModel |
QStringListModel (QObject * parent = nullptr) | |
QStringListModel (const QStringList & strings , QObject * parent = nullptr) | |
void | setStringList (const QStringList & strings ) |
QStringList | stringList () const |
virtual QVariant | data (const QModelIndex & index , int role = Qt::DisplayRole) const override |
virtual Qt::ItemFlags | flags (const QModelIndex & index ) const override |
virtual bool | insertRows (int row , int count , const QModelIndex & parent = QModelIndex()) override |
virtual bool | removeRows (int row , int count , const QModelIndex & parent = QModelIndex()) override |
virtual int | rowCount (const QModelIndex & parent = QModelIndex()) const override |
virtual bool | setData (const QModelIndex & index , const QVariant & value , int role = Qt::EditRole) override |
virtual QModelIndex | sibling (int row , int column , const QModelIndex & idx ) const override |
virtual void | sort (int column , Qt::SortOrder order = Qt::AscendingOrder) override |
virtual Qt::DropActions | supportedDropActions () const override |
const QMetaObject | staticMetaObject |
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 ,和 模型类 .
构造字符串列表模型采用给定 parent .
构造的字符串列表模型包含指定 strings 采用给定 parent .
[override virtual]
QVariant
QStringListModel::
data
(const
QModelIndex
&
index
,
int
role
= Qt::DisplayRole) const
重实现自 QAbstractItemModel::data ().
返回数据为指定 role ,从项采用给定 index .
若视图请求无效索引,则返回无效变体。
另请参阅 setData ().
[override virtual]
Qt::ItemFlags
QStringListModel::
flags
(const
QModelIndex
&
index
) const
重实现自 QAbstractListModel::flags ().
Returns the flags for the item with the given index .
Valid items are enabled, selectable, editable, drag enabled and drop enabled.
另请参阅 QAbstractItemModel::flags ().
[override virtual]
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 ().
[override virtual]
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 ().
[override 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 ().
[override virtual]
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 ().
将模型的内部字符串列表设为 strings 。模型将通知任何附加视图其底层数据已改变。
另请参阅 stringList () 和 dataChanged ().
[override virtual]
QModelIndex
QStringListModel::
sibling
(
int
row
,
int
column
, const
QModelIndex
&
idx
) const
重实现自 QAbstractListModel::sibling ().
[override virtual]
void
QStringListModel::
sort
(
int
column
,
Qt::SortOrder
order
= Qt::AscendingOrder)
重实现自 QAbstractItemModel::sort ().
返回模型用于存储数据的字符串列表。
另请参阅 setStringList ().
[override virtual]
Qt::DropActions
QStringListModel::
supportedDropActions
() const