DataModel

class qte.DataModel(titles=None)

The DataModel works on the premise that the data itself is stored and managed in some sort of python structure, for example a list. The data is assume to be essentially tabular with defined columns. The most important method is source, which returns an iterator over source records and is internally cached by the model to improve performance. source can be re-implemented through inheritance, or by simply assigning the name to a function, e.g.:

mymodel.source = lambda: iter(mydata)

The default implemented returns the same list every time, so it may be used to assign static data, e.g.:

mymodel.source().append(['new row'])

Each row in the table is represented by an item returned by source. The only requirement of the source items are that they should also be iterable.

Columns are defined by setting a list of column titles in the constructor or to DataModel.titles.

Members

Properties

DataModel.titles

An ordered list of column titles.

New Methods

DataModel.cache_refresh()

Force a cache refresh now.

DataModel.record(row)

Return the record currently appearing on a row.

Parameters:row – Integer row number.
Returns:A record
DataModel.setFlags(column, flags)

A convenience method to set flags for column.

Flags may be set either as an bitwise-or combination of PySide.QtCore.Qt.ItemFlags or as a space-separated list of any of the following strings.

String Qt.ItemFlag Description
selectable ItemIsSelectable It can be selected.
editable ItemIsEditable It can be edited.
drag ItemIsDragEnabled It can be dragged.
drop ItemIsDropEnabled It can be used as a drop target.
checkable ItemIsUserCheckable It can be checked or unchecked by the user.
enabled ItemIsEnabled The user can interact with the item.
tristate ItemIsTristate The item is checkable with three separate states.
DataModel.setValue(record, column, value)

Set the value in record for a specific column to value. By default, this assigns value using record[column] = value. This should never be called directly, or the PySide.QtGui.~QAbstractTableModel.dataChanged signal will not be emitted.

Parameters:
  • record – A record in source.
  • column – The column number.
  • value – The value to store in the record.
Returns:

True if the value was stored successfully.

DataModel.source()

Return an iterator over source data that this model represents. The default implementation returns the same list on every call.

DataModel.value(record, column)

Return the value stored in record for a specific column. By default, this uses index lookup on the column number, i.e record[column].

Parameters:
  • record – A record in source.
  • column – The column number.
Returns:

The value stored in the record.

Re-implemented Methods

DataModel.columnCount(parent=None)

Return the number of columns as determined from titles.

parent is superfluous and is ignored. It is only provided for Qt compatibility.

DataModel.data(index, role=<class 'DisplayRole'>)

Return the data in source for Qt.DisplayRole and Qt.EditRole.

DataModel.flags(index)

Return PySide.QtCore.Qt.ItemFlags for a cell.

By default, all cells are selectable, editable and enabled.

See also

setFlags

DataModel.headerData(section, orientation, role)

Return header information.

For horizontal headers and Qt.DisplayRole, return the relevant item in titles.

DataModel.rowCount(parent=None)

Return the number of visible rows under parent.

parent is superfluous and is ignored. It is only provided for Qt compatibility.

DataModel.setData(index, value, role)

This has been re-implemented to call setValue for Qt.EditRole.

Project Versions

Table Of Contents

Previous topic

ComboBox

Next topic

DataView

This Page