Skip to content

PythonQt.Qt.QDataWidgetMapper

QDataWidgetMapper

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

Detailed Description

QDataWidgetMapper can be used to create data-aware widgets by mapping them to sections of an item model. A section is a column of a model if the orientation is horizontal (the default), otherwise a row.

Every time the current index changes, each widget is updated with data from the model via the property specified when its mapping was made. If the user edits the contents of a widget, the changes are read using the same property and written back to the model. By default, each widget's user property is used to transfer data between the model and the widget. Since Qt 4.3, an additional addMapping() function enables a named property to be used instead of the default user property.

It is possible to set an item delegate to support custom widgets. By default, a QItemDelegate is used to synchronize the model with the widgets.

Let us assume that we have an item model named model with the following contents:

1 Qt Norway Oslo
2 Qt Australia Brisbane
3 Qt USA Palo Alto
4 Qt China Beijing
5 Qt Germany Berlin

The following code will map the columns of the model to widgets called mySpinBox, myLineEdit and myCountryChooser:

QDataWidgetMapper *mapper = new QDataWidgetMapper;
mapper->setModel(model);
mapper->addMapping(mySpinBox, 0);
mapper->addMapping(myLineEdit, 1);
mapper->addMapping(myCountryChooser, 2);
mapper->toFirst();

After the call to toFirst(), mySpinBox displays the value 1, myLineEdit displays Qt Norway and myCountryChooser displays Oslo. The navigational functions toFirst(), toNext(), toPrevious(), toLast() and setCurrentIndex() can be used to navigate in the model and update the widgets with contents from the model.

The setRootIndex() function enables a particular item in a model to be specified as the root index - children of this item will be mapped to the relevant widgets in the user interface.

QDataWidgetMapper supports two submit policies, AutoSubmit and ManualSubmit. AutoSubmit will update the model as soon as the current widget loses focus, ManualSubmit will not update the model unless submit() is called. ManualSubmit is useful when displaying a dialog that lets the user cancel all modifications. Also, other views that display the model won't update until the user finishes all their modifications and submits.

Note that QDataWidgetMapper keeps track of external modifications. If the contents of the model are updated in another module of the application, the widgets are updated as well.

Source: https://doc.qt.io/archives/qt-5.15/qdatawidgetmapper.html

Complete member index

Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.

Member Kind Signature Summary
AutoSubmit attribute Any (shared captured text)
ManualSubmit attribute Any (shared captured text)
SubmitPolicy attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
__init__ function (self, *args: Any, **kwargs: Any) -> None Native constructor; consult class documentation for supported overloads. (shared captured text)
addMapping function (self, widget: Any, section: int, propertyName: Any) -> None X.addMapping(widget, section, propertyName) (shared captured text)
blockSignals function (self, b: Any) -> bool X.blockSignals(b) -> bool (shared captured text)
childEvent function (self, event: Any) -> Any (shared captured text)
children function (self) -> tuple X.children() -> tuple (shared captured text)
className function (self, *args: Any, **kwargs: Any) -> Any Return the classname of the object (shared captured text)
clearMapping function (self) -> None Clears all mappings. (shared captured text)
connect function (self, signal: Any, receiver: Any, slot: Any, type: Any) -> bool X.connect(signal, receiver, slot, type) -> bool (shared captured text)
currentIndex attribute int This property holds the current row or column (shared captured text)
currentIndexChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QDataWidgetMapper.currentIndexChanged; argument details are not documented.
customEvent function (self, event: Any) -> Any (shared captured text)
delete function (self, *args: Any, **kwargs: Any) -> Any Deletes the C++ object (at your own risk, my friend!) (shared captured text)
deleteLater function (self) -> Any (shared captured text)
destroyed function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QDataWidgetMapper.destroyed; argument details are not documented.
disconnect function (self, signal: Any, receiver: Any, slot: Any) -> bool X.disconnect(signal, receiver, slot) -> bool (shared captured text)
dumpObjectInfo function (self) -> Any (shared captured text)
dumpObjectTree function (self) -> Any (shared captured text)
dynamicPropertyNames function (self) -> Any (shared captured text)
event function (self, event: Any) -> bool X.event(event) -> bool (shared captured text)
eventFilter function (self, watched: Any, event: Any) -> bool X.eventFilter(watched, event) -> bool (shared captured text)
findChild function (self, type: Any, name: Any) -> Any X.findChild(type, name) -> PythonQt.private.QObject (shared captured text)
findChildren function (self, type: Any, name: Any) -> tuple X.findChildren(type, name) -> tuple (shared captured text)
help function (self, *args: Any, **kwargs: Any) -> Any Shows the help of available methods for this class (shared captured text)
inherits function (self, *args: Any, **kwargs: Any) -> Any Returns if the class inherits or is of given type name (shared captured text)
installEventFilter function (self, filterObj: Any) -> Any (shared captured text)
isSignalConnected function (self, signal: Any) -> bool X.isSignalConnected(signal) -> bool (shared captured text)
isWidgetType function (self) -> bool X.isWidgetType() -> bool (shared captured text)
isWindowType function (self) -> bool X.isWindowType() -> bool (shared captured text)
itemDelegate function (self) -> Any X.itemDelegate() -> PythonQt.QtGui.QAbstractItemDelegate (shared captured text)
killTimer function (self, id: Any) -> Any (shared captured text)
mappedPropertyName function (self, widget: Any) -> Any X.mappedPropertyName(widget) -> PythonQt.QtCore.QByteArray (shared captured text)
mappedSection function (self, widget: Any) -> int X.mappedSection(widget) -> int (shared captured text)
mappedWidgetAt function (self, section: int) -> Any X.mappedWidgetAt(section) -> PythonQt.QtGui.QWidget (shared captured text)
metaObject function (self) -> Any X.metaObject() -> PythonQt.QtCore.QMetaObject (shared captured text)
model function (self) -> Any X.model() -> PythonQt.QtCore.QAbstractItemModel (shared captured text)
moveToThread function (self, thread: Any) -> Any (shared captured text)
objectName attribute Any (shared captured text)
objectNameChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QDataWidgetMapper.objectNameChanged; argument details are not documented.
orientation attribute Any This property holds the orientation of the model (shared captured text)
parent function (self) -> Any X.parent() -> PythonQt.private.QObject (shared captured text)
property function (self, name: Any) -> Any X.property(name) -> object (shared captured text)
removeEventFilter function (self, obj: Any) -> Any (shared captured text)
removeMapping function (self, widget: Any) -> None Removes the mapping for the given widget. (shared captured text)
revert function (self) -> None Repopulates all widgets with the current data of the model. (shared captured text)
rootIndex function (self) -> Any X.rootIndex() -> PythonQt.QtCore.QModelIndex (shared captured text)
sender function (self) -> Any X.sender() -> PythonQt.private.QObject (shared captured text)
senderSignalIndex function (self) -> int X.senderSignalIndex() -> int (shared captured text)
setCurrentIndex function (self, index: int) -> None (shared captured text)
setCurrentModelIndex function (self, index: Any) -> None Sets the current index to the row of the index if the orientation is horizontal (the default), otherwise to the column of the index. (shared captured text)
setItemDelegate function (self, delegate: Any) -> None Sets the item delegate to delegate. (shared captured text)
setModel function (self, model: Any) -> None Sets the current model to model. (shared captured text)
setObjectName function (self, name: Any) -> Any (shared captured text)
setOrientation function (self, aOrientation: Any) -> None (shared captured text)
setParent function (self, parent: Any) -> Any (shared captured text)
setProperty function (self, name: Any, value: Any) -> bool X.setProperty(name, value) -> bool (shared captured text)
setRootIndex function (self, index: Any) -> None Sets the root item to index. (shared captured text)
setSubmitPolicy function (self, policy: Any) -> None (shared captured text)
signalsBlocked function (self) -> bool X.signalsBlocked() -> bool (shared captured text)
startTimer function (self, interval: Any, timerType: Any) -> int X.startTimer(interval, timerType) -> int (shared captured text)
submit function (self) -> bool X.submit() -> bool (shared captured text)
submitPolicy attribute Any This property holds the current submit policy (shared captured text)
thread function (self) -> Any (shared captured text)
timerEvent function (self, event: Any) -> Any (shared captured text)
toFirst function (self) -> None Populates the widgets with data from the first row of the model if the orientation is horizontal (the default), otherwise with data from the first column. (shared captured text)
toLast function (self) -> None Populates the widgets with data from the last row of the model if the orientation is horizontal (the default), otherwise with data from the last column. (shared captured text)
toNext function (self) -> None Populates the widgets with data from the next row of the model if the orientation is horizontal (the default), otherwise with data from the next column. (shared captured text)
toPrevious function (self) -> None Populates the widgets with data from the previous row of the model if the orientation is horizontal (the default), otherwise with data from the previous column. (shared captured text)
tr function (self, text: Any, ambig: Any, n: Any) -> str X.tr(text, ambig, n) -> str (shared captured text)