QStringListModel类提供了一个模型,该模型向视图提供字符串。
QStringListModel是一个可编辑的模型,可用于需要在视图小部件(如QListView或QComboBox)中显示多个字符串的简单情况。
该模型提供可编辑模型的所有标准函数,将字符串列表中的数据。
使用data()函数读取项数据,并使用setData()写入项数据。可以使用rowCount()函数找到行数(以及字符串列表中的项数)。
可以使用现有的字符串列表构造模型,也可以稍后使用setStringList()便利函数设置字符串。字符串也可以用insertRows()函数以通常的方式插入,并用removeows()删除。字符串列表的内容可以使用stringList()便利函数检索。
An example usage of QStringListModel:
QStringListModel *model = new QStringListModel();
QStringList list;
list << "a" << "b" << "c";
model->setStringList(list);
Reimplemented Public Functions
virtual QVariant data(const QModelIndex & index, int role) 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