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