Skip to content

DataWidgetMapper

Base classes

Name Children Inherits
ObjectMixin
prettyqt.core.object
QDataWidgetMapper
PySide6.QtWidgets
QDataWidgetMapper(self, /, parent: PySide6.QtCore.QObject | None \= None, *, currentIndex: int | None \= None, orientation: PySide6.QtCore.Qt.Orientation | None \= None, submitPolicy: PySide6.QtWidgets.QDataWidgetMapper.SubmitPolicy | None \= None) -> None

â‹” Inheritance diagram

graph TD
  3474017354["widgets.DataWidgetMapper"]
  3227531497["core.ObjectMixin"]
  2751680898["builtins.object"]
  957334295["QtWidgets.QDataWidgetMapper"]
  3984060476["QtCore.QObject"]
  37984305["Shiboken.Object"]
  3227531497 --> 3474017354
  2751680898 --> 3227531497
  957334295 --> 3474017354
  3984060476 --> 957334295
  37984305 --> 3984060476
  2751680898 --> 37984305

🛈 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 bytes(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))

:fa-brands-github: Show source on GitHub