QStringListModel Class Reference

[ QtGui module]

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

继承 QAbstractListModel .

Inherited by QHelpIndexModel .

方法


详细描述

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 .

The model provides all the standard functions of an editable model, representing the data in the string list as a model with one column and a number of rows equal to the number of items in the list.

Model indexes corresponding to items are obtained with the index() function, and item flags are obtained with flags (). Item data is read with the data () function and written with setData (). The number of rows (and number of items in the string list) can be found with the rowCount () 函数。

The model can be constructed with an existing string list, or strings can be set later with the setStringList () convenience function. Strings can also be inserted in the usual way 采用 insertRows () function, and removed with removeRows (). The contents of the string list can be retrieved with the stringList () convenience 函数。

An example usage of QStringListModel:

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

方法文档编制

QStringListModel.__init__ ( self , QObject   parent  = None)

parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a string list model with the given parent .

QStringListModel.__init__ ( self , QStringList  strings , QObject   parent  = None)

parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a string list model containing the specified strings with the given parent .

QVariant QStringListModel.data ( self , QModelIndex   index , int  role )

重实现自 QAbstractItemModel.data ().

Returns data for the specified role , from the item with the given index .

If the view requests an invalid index, an invalid variant is returned.

另请参阅 setData ().

Qt.ItemFlags QStringListModel.flags ( self , QModelIndex   index )

重实现自 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 ( self , int  row , int  count , 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 ().

bool QStringListModel.removeRows ( self , int  row , int  count , 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 ().

int QStringListModel.rowCount ( self , QModelIndex   parent  = QModelIndex())

重实现自 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 ( self , QModelIndex   index , QVariant  value , int  role  = Qt.EditRole)

重实现自 QAbstractItemModel.setData ().

Sets the data for the specified role in the item with the given index in the model, to the provided value .

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

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

QStringListModel.setStringList ( self , QStringList  strings )

Sets the model's internal string list to strings 。 model will notify any attached views that its underlying data has 改变。

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

QStringListModel.sort ( self , int  column , Qt.SortOrder   order  = Qt.AscendingOrder)

重实现自 QAbstractItemModel.sort ().

QStringList QStringListModel.stringList ( self )

Returns the string list used by the model to store data.

另请参阅 setStringList ().

Qt.DropActions QStringListModel.supportedDropActions ( self )

重实现自 QAbstractItemModel.supportedDropActions ().