Skip to content

DataWidgetMapper

Qt Base Class: QDataWidgetMapper

Signature: QDataWidgetMapper(self, parent: Optional[PySide6.QtCore.QObject] = None) -> None

Base classes

Name Children Inherits
ObjectMixin
prettyqt.core.object
QDataWidgetMapper
PySide6.QtWidgets
QDataWidgetMapper(self, parent: Optional[PySide6.QtCore.QObject] \= None) -> None

⋔ Inheritance diagram

graph TD
  1473296390576["widgets.DataWidgetMapper"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473293752656["QtWidgets.QDataWidgetMapper"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473299815024 --> 1473296390576
  140713234304496 --> 1473299815024
  1473293752656 --> 1473296390576
  1473288842240 --> 1473293752656
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208

🛈 DocStrings

Bases: ObjectMixin, QDataWidgetMapper

Mapping between a section of a data model to widgets.

Source code in prettyqt\widgets\datawidgetmapper.py
class DataWidgetMapper(core.ObjectMixin, widgets.QDataWidgetMapper):
    """Mapping between a section of a data model to widgets."""

    def __setitem__(self, key: int, value: widgets.QWidget):
        self.addMapping(value, key)

    def __getitem__(self, key: int) -> widgets.QWidget:
        return self.mappedWidgetAt(key)

    def __delitem__(self, key_or_widget: int | widgets.QWidget):
        widget = (
            self.mappedWidgetAt(key_or_widget)
            if isinstance(key_or_widget, int)
            else key_or_widget
        )
        self.removeMapping(widget)

    def _get_map(self):
        maps = super()._get_map()
        maps |= {"submitPolicy": SUBMIT_POLICY, "orientation": constants.ORIENTATION}
        return maps

    def set_orientation(
        self, orientation: constants.OrientationStr | constants.Orientation
    ):
        """Set the orientation of the data widget mapper.

        Args:
            orientation: orientation for the data widget mapper
        """
        self.setOrientation(constants.ORIENTATION.get_enum_value(orientation))

    def get_orientation(self) -> constants.OrientationStr:
        """Return current orientation.

        Returns:
            orientation
        """
        return constants.ORIENTATION.inverse[self.orientation()]

    def set_submit_policy(
        self, policy: SubmitPolicyStr | widgets.QDataWidgetMapper.SubmitPolicy
    ):
        """Set the submit policy of the mapper.

        Args:
            policy: submit_policy for the data widget mapper
        """
        self.setSubmitPolicy(SUBMIT_POLICY.get_enum_value(policy))

    def get_submit_policy(self) -> SubmitPolicyStr:
        """Return current submit policy.

        Returns:
            submit policy
        """
        return SUBMIT_POLICY.inverse[self.submitPolicy()]

    def add_mapping(
        self, widget: widgets.QWidget, section: int, property_name: str | None = None
    ):
        if property_name is None:
            self.addMapping(widget, section)
        else:
            ba = core.QByteArray(property_name.encode())
            self.addMapping(widget, section, ba)

    def get_mapped_property_name(self, widget: widgets.QWidget) -> str:
        return self.mappedPropertyName(widget).data().decode()

get_orientation() -> constants.OrientationStr

Return current orientation.

Source code in prettyqt\widgets\datawidgetmapper.py
def get_orientation(self) -> constants.OrientationStr:
    """Return current orientation.

    Returns:
        orientation
    """
    return constants.ORIENTATION.inverse[self.orientation()]

get_submit_policy() -> SubmitPolicyStr

Return current submit policy.

Source code in prettyqt\widgets\datawidgetmapper.py
def get_submit_policy(self) -> SubmitPolicyStr:
    """Return current submit policy.

    Returns:
        submit policy
    """
    return SUBMIT_POLICY.inverse[self.submitPolicy()]

set_orientation(orientation: constants.OrientationStr | constants.Orientation)

Set the orientation of the data widget mapper.

Parameters:

Name Type Description Default
orientation OrientationStr | Orientation

orientation for the data widget mapper

required
Source code in prettyqt\widgets\datawidgetmapper.py
def set_orientation(
    self, orientation: constants.OrientationStr | constants.Orientation
):
    """Set the orientation of the data widget mapper.

    Args:
        orientation: orientation for the data widget mapper
    """
    self.setOrientation(constants.ORIENTATION.get_enum_value(orientation))

set_submit_policy(policy: SubmitPolicyStr | widgets.QDataWidgetMapper.SubmitPolicy)

Set the submit policy of the mapper.

Parameters:

Name Type Description Default
policy SubmitPolicyStr | SubmitPolicy

submit_policy for the data widget mapper

required
Source code in prettyqt\widgets\datawidgetmapper.py
def set_submit_policy(
    self, policy: SubmitPolicyStr | widgets.QDataWidgetMapper.SubmitPolicy
):
    """Set the submit policy of the mapper.

    Args:
        policy: submit_policy for the data widget mapper
    """
    self.setSubmitPolicy(SUBMIT_POLICY.get_enum_value(policy))

⌗ Property table

Qt Property Type Doc
objectName QString
currentIndex int
orientation Qt::Orientation
submitPolicy QDataWidgetMapper::SubmitPolicy