- class QStringListModel#
The
QStringListModel
class provides a model that supplies strings to views. More…Inherited by:
QHelpIndexModel
Synopsis#
Methods#
def
__init__()
def
setStringList()
def
stringList()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description#
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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 or a 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 withflags()
. Item data is read with thedata()
function and written withsetData()
. The number of rows (and number of items in the string list) can be found with therowCount()
function.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 with theinsertRows()
function, and removed withremoveRows()
. The contents of the string list can be retrieved with thestringList()
convenience function.An example usage of
QStringListModel
:model = QStringListModel() list = QStringList() list << "a" << "b" << "c" model.setStringList(list)
See also
QAbstractListModel
QAbstractItemModel
Model Classes
Constructs a string list model with the given
parent
.- __init__(strings[, parent=None])
- Parameters:
strings – list of strings
parent –
QObject
Constructs a string list model containing the specified
strings
with the givenparent
.- setStringList(strings)#
- Parameters:
strings – list of strings
Sets the model’s internal string list to
strings
. The model will notify any attached views that its underlying data has changed.See also
stringList()
dataChanged()
- stringList()#
- Return type:
list of strings
Returns the string list used by the model to store data.
See also