Skip to content

itemdelegates

Class info

Classes

Name Children Inherits
ButtonDelegate
prettyqt.itemdelegates.buttondelegate
Delegate to show a button inside a table cell.
    EditorDelegate
    prettyqt.itemdelegates.editordelegate
    Delegate which supports editing a large range of data types.
      HtmlItemDelegate
      prettyqt.itemdelegates.htmlitemdelegate
      Delegate do display HTML text.
        • BaseMarkupDelegate
        IconDelegate
        prettyqt.itemdelegates.icondelegate
        Delegate to paint QIcons, QPixmaps, QColors and QImages.
          MarkdownItemDelegate
          prettyqt.itemdelegates.htmlitemdelegate
          Delegate do display Markdown text.
            • BaseMarkupDelegate
            NoFocusDelegate
            prettyqt.itemdelegates.nofocusdelegate
            Delegate to remove dotted border on cell focus.
              ProgressBarDelegate
              prettyqt.itemdelegates.progressbardelegate
              Delegate to show a value in form of a progress bar.
                RadioDelegate
                prettyqt.itemdelegates.radiodelegate
                  RenderLinkDelegate
                  prettyqt.itemdelegates.renderlinkdelegate
                    StarDelegate
                    prettyqt.itemdelegates.stardelegate
                    A delegate class that allows us to render our star ratings.
                      WidgetDelegate
                      prettyqt.itemdelegates.widgetdelegate

                        🛈 DocStrings

                        Module containing custom delegate classes.

                        PrettyQt offers an extended Item delegate with support for a large number of different data types.

                        The following data types are supported:

                        • bool
                        • enum.Flag
                        • enum.Enum
                        • int
                        • float
                        • str
                        • range
                        • slice
                        • list of ints
                        • list of floats
                        • list of strings
                        • pathlib.Path
                        • re.Pattern
                        • datetime.date
                        • datetime.time
                        • datetime.datetime
                        • QtCore.QRegularExpression
                        • QtCore.QTime
                        • QtCore.QDate
                        • QtCore.QDateTime
                        • QtCore.QPoint
                        • QtCore.QPointF
                        • QtCore.QRect
                        • QtCore.QRectF
                        • QtCore.QRection
                        • QtCore.QKeyCombination
                        • QtCore.QLocale
                        • QtCore.QSize
                        • QtCore.QSizeF
                        • QtCore.QUrl
                        • QtGui.QFont
                        • QtGui.QKeySequence
                        • QtGui.QPalette
                        • QtGui.QColor
                        • QtGui.QBrush
                        • QtGui.QCursor
                        • QtGui.QIcon
                        • QtWidgets.QSizePolicy

                        If numpy is installed, the following types are supported, too:

                        • numpy.floating
                        • numpy.integer
                        • numpy.str_
                        • numpy.datetime64
                        • numpy.bool_

                        ButtonDelegate

                        Bases: StyledItemDelegate

                        Delegate to show a button inside a table cell.

                        Source code in prettyqt/itemdelegates/buttondelegate.py
                        class ButtonDelegate(widgets.StyledItemDelegate):
                            """Delegate to show a button inside a table cell."""
                        
                            ID = "button"
                        
                            def __init__(
                                self,
                                parent: widgets.QAbstractItemView,
                                role: constants.ItemDataRole = constants.USER_ROLE,
                            ):
                                super().__init__(parent)
                                parent.setMouseTracking(True)
                                self.btn = widgets.PushButton(parent=parent)
                                self.method_role = role
                                self.btn.hide()
                                self.current_edited_index = core.ModelIndex()
                                parent.entered.connect(self.cell_entered)
                        
                            #     parent.viewport().installEventFilter(self)
                        
                            # def eventFilter(self, source, event) -> bool:
                            #     if event.type() == event.Type.MouseMove:
                            #         return True
                            #     return super().eventFilter(source, event)
                        
                            def updateEditorGeometry(
                                self,
                                editor: widgets.QWidget,
                                option: widgets.QStyleOptionViewItem,
                                index: core.ModelIndex,
                            ):
                                editor.setGeometry(option.rect)
                        
                            def createEditor(
                                self,
                                parent: widgets.QWidget,
                                option: widgets.QStyleOptionViewItem,
                                index: core.ModelIndex,
                            ):
                                btn_callback = index.data(self.method_role)
                                if btn_callback is None:
                                    return None
                                text = index.data()
                                return widgets.PushButton(
                                    parent=parent,
                                    text="" if text is None else str(text),
                                    clicked=btn_callback,
                                )
                        
                            def setEditorData(self, editor: widgets.QWidget, index: core.ModelIndex):
                                pass
                                # editor.setProperty("test", "aa")
                                # editor.setText(index.data())
                        
                            def setModelData(
                                self,
                                editor: widgets.QWidget,
                                model: core.QAbstractItemModel,
                                index: core.ModelIndex,
                            ):
                                pass
                                # model.setData(index, editor.property("test"))
                        
                            def cell_entered(self, index: core.ModelIndex):
                                # index = self.parent().indexFromItem(item)
                                parent: widgets.QAbstractItemView = self.parent()  # type: ignore
                                if self.current_edited_index.isValid() and parent.isPersistentEditorOpen(
                                    self.current_edited_index
                                ):
                                    parent.closePersistentEditor(self.current_edited_index)
                                if parent.itemDelegateForIndex(index) is self:
                                    # if index.data(self.method_role) is not None:
                                    parent.openPersistentEditor(index)
                                    parent.setCurrentIndex(index)
                                self.current_edited_index = index
                        
                            def paint(
                                self,
                                painter: gui.QPainter,
                                option: widgets.QStyleOptionViewItem,
                                index: core.ModelIndex,
                            ):
                                if index.data(self.method_role) is None:
                                    super().paint(painter, option, index)
                                    return
                                self.btn.setGeometry(option.rect)
                                text = index.data()
                                self.btn.setText("" if text is None else str(text))
                                if option.state & widgets.Style.StateFlag.State_MouseOver:
                                    painter.fillRect(option.rect, option.palette.highlight())
                                if option.state & widgets.Style.StateFlag.State_Selected:
                                    painter.fillRect(option.rect, option.palette.highlight())
                                pixmap = self.btn.grab()
                                painter.drawPixmap(option.rect, pixmap)
                        

                        EditorDelegate

                        Bases: StyledItemDelegate

                        Delegate which supports editing a large range of data types.

                        Allows editing a large range of different types from Qt, builtin libraries as well as some Numpy types.

                        The Delegate also has an extended displayText method to show a repr-like string for different data types.

                        The following data types are supported:

                        • bool
                        • enum.Flag
                        • enum.Enum
                        • int
                        • float
                        • str
                        • range
                        • slice
                        • list of ints
                        • list of floats
                        • list of strings
                        • pathlib.Path
                        • re.Pattern
                        • datetime.date
                        • datetime.time
                        • datetime.datetime
                        • QtCore.QRegularExpression
                        • QtCore.QTime
                        • QtCore.QDate
                        • QtCore.QDateTime
                        • QtCore.QPoint
                        • QtCore.QPointF
                        • QtCore.QRect
                        • QtCore.QRectF
                        • QtCore.QRection
                        • QtCore.QKeyCombination
                        • QtCore.QLocale
                        • QtCore.QSize
                        • QtCore.QSizeF
                        • QtCore.QUrl
                        • QtGui.QFont
                        • QtGui.QKeySequence
                        • QtGui.QPalette
                        • QtGui.QColor
                        • QtGui.QBrush
                        • QtGui.QCursor
                        • QtGui.QIcon
                        • QtWidgets.QSizePolicy

                        If numpy is installed, the following types are supported, too:

                        • numpy.floating
                        • numpy.integer
                        • numpy.str_
                        • numpy.datetime64
                        • numpy.bool_
                        Source code in prettyqt/itemdelegates/editordelegate.py
                        class EditorDelegate(widgets.StyledItemDelegate):
                            """Delegate which supports editing a large range of data types.
                        
                            Allows editing a large range of different types from Qt, builtin libraries as well
                            as some Numpy types.
                        
                            The Delegate also has an extended displayText method to show a repr-like string for
                            different data types.
                        
                            The following data types are supported:
                        
                            * bool
                            * enum.Flag
                            * enum.Enum
                            * int
                            * float
                            * str
                            * range
                            * slice
                            * list of ints
                            * list of floats
                            * list of strings
                            * pathlib.Path
                            * re.Pattern
                            * datetime.date
                            * datetime.time
                            * datetime.datetime
                            * QtCore.QRegularExpression
                            * QtCore.QTime
                            * QtCore.QDate
                            * QtCore.QDateTime
                            * QtCore.QPoint
                            * QtCore.QPointF
                            * QtCore.QRect
                            * QtCore.QRectF
                            * QtCore.QRection
                            * QtCore.QKeyCombination
                            * QtCore.QLocale
                            * QtCore.QSize
                            * QtCore.QSizeF
                            * QtCore.QUrl
                            * QtGui.QFont
                            * QtGui.QKeySequence
                            * QtGui.QPalette
                            * QtGui.QColor
                            * QtGui.QBrush
                            * QtGui.QCursor
                            * QtGui.QIcon
                            * QtWidgets.QSizePolicy
                        
                            If numpy is installed, the following types are supported, too:
                        
                            * numpy.floating
                            * numpy.integer
                            * numpy.str_
                            * numpy.datetime64
                            * numpy.bool_
                        
                            """
                        
                            ID = "editor"
                        
                            def __init__(
                                self,
                                *args,
                                role: constants.ItemDataRole = constants.EDIT_ROLE,
                                validator: (
                                    gui.QValidator | widgets.lineedit.ValidatorStr | datatypes.PatternType | None
                                ) = None,
                                **kwargs,
                            ):
                                super().__init__(*args, **kwargs)
                                self._role = role
                                self._validator = validator
                        
                            def paint(
                                self,
                                painter: gui.QPainter,
                                option: widgets.QStyleOptionViewItem,
                                index: core.ModelIndex,
                            ):
                                # if not self.is_supported_type(value):
                                #     option = widgets.StyleOptionViewItem(option)
                                #     option.state &= ~widgets.QStyle.StateFlag.State_Enabled
                                from prettyqt import itemdelegates
                        
                                match value := self._data_for_index(index, self._role):
                                    case gui.QIcon():
                                        icon_delegate = itemdelegates.IconDelegate(role=self._role)
                                        icon_delegate.paint(painter, option, index)
                                        return
                                    case enum.Enum():  # PySide6 needs this when using Views
                                        option.text = value.name if value.name is not None else str(value)
                                        style = (
                                            option.widget.style()
                                            if option.widget is not None
                                            else widgets.Application.style()
                                        )
                                        style.drawControl(
                                            widgets.QStyle.ControlElement.CE_ItemViewItem, option, painter
                                        )
                                    case _:
                                        super().paint(painter, option, index)
                        
                            def createEditor(
                                self,
                                parent: widgets.QWidget,
                                option: widgets.QStyleOptionViewItem,
                                index: core.ModelIndex,
                            ):
                                val = self._data_for_index(index, self._role)
                                logger.info("creating editor for %r...", val)
                                if isinstance(val, list):
                                    widget = datatypes.get_editor_for_value_list(val, parent)
                                else:
                                    widget = datatypes.get_editor_for_value(val, parent)
                                if widget is None:
                                    logger.warning("Could not find editor for %r (%s)", val, type(val))
                                    return None
                                if self._validator and isinstance(
                                    widget, widgets.LineEdit | widgets.AbstractSpinBoxMixin
                                ):
                                    widget.set_validator(self._validator, append=True)
                        
                                widget.setAutoFillBackground(True)
                                widget.set_focus_policy("strong")
                                return widget
                        
                            def setEditorData(self, editor: widgets.QWidget, index: core.ModelIndex):
                                value = self._data_for_index(index, self._role)
                                logger.info("setting data for %r to %r", editor, value)
                                # editors are prettyqt editor widgets with get_value() / set_value()
                                cast("Any", editor).set_value(value)
                        
                            def setModelData(
                                self,
                                editor: widgets.QWidget,
                                model: core.QAbstractItemModel,
                                index: core.ModelIndex,
                            ):
                                if (value := cast("Any", editor).get_value()) is not None:
                                    logger.info("setting data for %r to %r", model, value)
                                    model.setData(index, value, self._role)
                                    # self.closeEditor.emit(editor, self.EndEditHint.NoHint)
                                    self.commitData.emit(editor)
                        
                            def displayText(self, value: Any, locale: core.QLocale) -> str:
                                return datatypes.to_string(value, locale)
                        

                        HtmlItemDelegate

                        Bases: BaseMarkupDelegate

                        Delegate do display HTML text.

                        Source code in prettyqt/itemdelegates/htmlitemdelegate.py
                        class HtmlItemDelegate(BaseMarkupDelegate):
                            """Delegate do display HTML text."""
                        
                            ID = "html"
                        
                            def set_text(self, text: str):
                                self.doc.setHtml(text)
                        

                        IconDelegate

                        Bases: StyledItemDelegate

                        Delegate to paint QIcons, QPixmaps, QColors and QImages.

                        Source code in prettyqt/itemdelegates/icondelegate.py
                        class IconDelegate(widgets.StyledItemDelegate):
                            """Delegate to paint QIcons, QPixmaps, QColors and QImages."""
                        
                            ID = "icon"
                        
                            def __init__(self, role: constants.ItemDataRole = constants.USER_ROLE, **kwargs):
                                self._role = role
                                self.margin = 10
                                super().__init__(**kwargs)
                        
                            def paint(
                                self,
                                painter: gui.QPainter,
                                option: widgets.QStyleOptionViewItem,
                                index: core.ModelIndex,
                            ):
                                """Override to paint an icon based on given Pixmap / Color / Icon.
                        
                                Pixmap / Color / Icon must be set to '_role'
                        
                                Args:
                                    painter (gui.QPainter): painter to paint the icon
                                    option (widgets.QStyleOptionViewItem): state of the item to be displayed
                                    index (core.ModelIndex): index which gets decorated
                                """
                                super().paint(painter, option, index)
                                value = index.data(self._role)
                                if not value:
                                    return
                                mode = gui.Icon.Mode.Normal
                        
                                if not option.state & widgets.Style.StateFlag.State_Enabled:
                                    mode = gui.Icon.Mode.Disabled
                                elif option.state & widgets.Style.StateFlag.State_Selected:
                                    mode = gui.Icon.Mode.Selected
                                match value:
                                    case gui.QPixmap():
                                        icon = gui.QIcon(value)
                                        option.decorationSize = value.size() / value.devicePixelRatio()
                        
                                    case gui.QColor():
                                        pixmap = gui.QPixmap(option.decorationSize)
                                        pixmap.fill(value)
                                        icon = gui.QIcon(pixmap)
                        
                                    case gui.QImage():
                                        icon = gui.QIcon(gui.QPixmap.fromImage(value))
                                        option.decorationSize = value.size() / value.devicePixelRatio()
                        
                                    case gui.QIcon():
                                        icon = value
                                        is_on = option.state & widgets.Style.StateFlag.State_Open
                                        state = gui.Icon.State.On if is_on else gui.Icon.State.Off
                                        actual_size = icon.actualSize(option.decorationSize, mode, state)
                                        option.decorationSize = option.decorationSize.boundedTo(actual_size)
                                    case _:
                                        raise ValueError(value)
                                r = core.Rect(core.Point(), cast("core.QSize", option.decorationSize))
                                r.moveCenter(option.rect.center())
                                r.setRight(option.rect.right() - self.margin)
                                state = (
                                    gui.Icon.State.On
                                    if option.state & widgets.Style.StateFlag.State_Open
                                    else gui.Icon.State.Off
                                )
                                alignment = constants.ALIGN_RIGHT | constants.ALIGN_V_CENTER
                                icon.paint(painter, r, alignment, mode, state)
                        

                        paint(painter: gui.QPainter, option: widgets.QStyleOptionViewItem, index: core.ModelIndex)

                        Override to paint an icon based on given Pixmap / Color / Icon.

                        Pixmap / Color / Icon must be set to '_role'

                        Parameters:

                        Name Type Description Default
                        painter QPainter

                        painter to paint the icon

                        required
                        option QStyleOptionViewItem

                        state of the item to be displayed

                        required
                        index ModelIndex

                        index which gets decorated

                        required
                        Source code in prettyqt/itemdelegates/icondelegate.py
                        def paint(
                            self,
                            painter: gui.QPainter,
                            option: widgets.QStyleOptionViewItem,
                            index: core.ModelIndex,
                        ):
                            """Override to paint an icon based on given Pixmap / Color / Icon.
                        
                            Pixmap / Color / Icon must be set to '_role'
                        
                            Args:
                                painter (gui.QPainter): painter to paint the icon
                                option (widgets.QStyleOptionViewItem): state of the item to be displayed
                                index (core.ModelIndex): index which gets decorated
                            """
                            super().paint(painter, option, index)
                            value = index.data(self._role)
                            if not value:
                                return
                            mode = gui.Icon.Mode.Normal
                        
                            if not option.state & widgets.Style.StateFlag.State_Enabled:
                                mode = gui.Icon.Mode.Disabled
                            elif option.state & widgets.Style.StateFlag.State_Selected:
                                mode = gui.Icon.Mode.Selected
                            match value:
                                case gui.QPixmap():
                                    icon = gui.QIcon(value)
                                    option.decorationSize = value.size() / value.devicePixelRatio()
                        
                                case gui.QColor():
                                    pixmap = gui.QPixmap(option.decorationSize)
                                    pixmap.fill(value)
                                    icon = gui.QIcon(pixmap)
                        
                                case gui.QImage():
                                    icon = gui.QIcon(gui.QPixmap.fromImage(value))
                                    option.decorationSize = value.size() / value.devicePixelRatio()
                        
                                case gui.QIcon():
                                    icon = value
                                    is_on = option.state & widgets.Style.StateFlag.State_Open
                                    state = gui.Icon.State.On if is_on else gui.Icon.State.Off
                                    actual_size = icon.actualSize(option.decorationSize, mode, state)
                                    option.decorationSize = option.decorationSize.boundedTo(actual_size)
                                case _:
                                    raise ValueError(value)
                            r = core.Rect(core.Point(), cast("core.QSize", option.decorationSize))
                            r.moveCenter(option.rect.center())
                            r.setRight(option.rect.right() - self.margin)
                            state = (
                                gui.Icon.State.On
                                if option.state & widgets.Style.StateFlag.State_Open
                                else gui.Icon.State.Off
                            )
                            alignment = constants.ALIGN_RIGHT | constants.ALIGN_V_CENTER
                            icon.paint(painter, r, alignment, mode, state)
                        

                        MarkdownItemDelegate

                        Bases: BaseMarkupDelegate

                        Delegate do display Markdown text.

                        Source code in prettyqt/itemdelegates/htmlitemdelegate.py
                        class MarkdownItemDelegate(BaseMarkupDelegate):
                            """Delegate do display Markdown text."""
                        
                            ID = "markdown"
                        
                            def __init__(self, *args, mode: str = "github", **kwargs):
                                super().__init__(*args, **kwargs)
                                self._mode = mode
                        
                            def set_text(self, text: str):
                                Feat = self.doc.MarkdownFeature  # noqa: N806
                                match self._mode:
                                    case "no_html":
                                        self.doc.setMarkdown(text, Feat.MarkdownNoHTML)
                                    case "commonmark":
                                        self.doc.setMarkdown(text, Feat.MarkdownDialectCommonMark)
                                    case "github" | "":
                                        self.doc.setMarkdown(text, Feat.MarkdownDialectGitHub)
                                    case _:
                                        raise ValueError(self._mode)
                        
                            def get_markup_mode(self) -> str:
                                return self._mode
                        
                            def set_markup_mode(self, mode: str):
                                self._mode = mode
                        
                            markup_mode = core.Property(
                                str,
                                get_markup_mode,
                                set_markup_mode,
                                doc="Which markdown dialect to use.",
                            )
                        

                        NoFocusDelegate

                        Bases: StyledItemDelegate

                        Delegate to remove dotted border on cell focus.

                        Source code in prettyqt/itemdelegates/nofocusdelegate.py
                        class NoFocusDelegate(widgets.StyledItemDelegate):
                            """Delegate to remove dotted border on cell focus."""
                        
                            ID = "no_focus"
                        
                            def paint(
                                self,
                                painter: gui.QPainter,
                                option: widgets.QStyleOptionViewItem,
                                index: core.ModelIndex,
                            ):
                                if option.state & widgets.Style.StateFlag.State_HasFocus:
                                    option.state = option.state ^ widgets.Style.StateFlag.State_HasFocus
                                super().paint(painter, option, index)
                        

                        ProgressBarDelegate

                        Bases: StyledItemDelegate

                        Delegate to show a value in form of a progress bar.

                        Source code in prettyqt/itemdelegates/progressbardelegate.py
                        class ProgressBarDelegate(widgets.StyledItemDelegate):
                            """Delegate to show a value in form of a progress bar."""
                        
                            ID = "progress_bar"
                        
                            def __init__(
                                self,
                                role: constants.ItemDataRole = constants.DISPLAY_ROLE,
                                total: int = 100,
                                **kwargs,
                            ):
                                self._role = role
                                self._total = total
                                super().__init__(**kwargs)
                        
                            def paint(
                                self,
                                painter: gui.QPainter,
                                option: widgets.QStyleOptionViewItem,
                                index: core.ModelIndex,
                            ):
                                progress = index.data(self._role)
                                if progress is None:
                                    return
                                opt = widgets.StyleOptionProgressBar()
                                opt.rect = option.rect
                                opt.minimum = 0
                                opt.maximum = self._total
                                opt.progress = int(progress)
                                pct = round(progress * 100 / self._total) if self._total else 0
                                opt.text = f"{pct}%"
                                opt.textVisible = True
                                opt.state |= widgets.Style.StateFlag.State_Horizontal
                                widgets.Application.style().drawControl(
                                    widgets.Style.ControlElement.CE_ProgressBar, opt, painter
                                )
                        
                            def set_total(self, total: int):
                                self._total = total
                        
                            def get_total(self) -> int:
                                return self._total
                        
                            def set_role(self, role: constants.ItemDataRole):
                                self._role = role
                        
                            def get_role(self) -> constants.ItemDataRole:
                                return self._role
                        
                            total = core.Property(
                                int,
                                get_total,
                                set_total,
                                doc="Total value for the progress bar",
                            )
                            role = core.Property(
                                constants.ItemDataRole,
                                get_role,
                                set_role,
                                doc="Role to use for the progress bar value",
                            )
                        

                        StarDelegate

                        Bases: StyledItemDelegate

                        A delegate class that allows us to render our star ratings.

                        Source code in prettyqt/itemdelegates/stardelegate.py
                        class StarDelegate(widgets.StyledItemDelegate):
                            """A delegate class that allows us to render our star ratings."""
                        
                            ID = "star"
                        
                            def paint(
                                self,
                                painter: gui.QPainter,
                                option: widgets.QStyleOptionViewItem,
                                index: core.ModelIndex,
                            ):
                                rating = index.data()
                                if rating is None:
                                    super().paint(painter, option, index)
                                    return
                                star_rating = StarRating(rating)
                        
                                # If the row is currently selected, we need to make sure we
                                # paint the background accordingly.
                                if option.state & widgets.Style.StateFlag.State_Selected:
                                    # The original C++ example used option.palette.foreground() to
                                    # get the brush for painting, but there are a couple of
                                    # problems with that:
                                    #   - foreground() is obsolete now, use windowText() instead
                                    #   - more importantly, windowText() just returns a brush
                                    #     containing a flat color, where sometimes the style
                                    #     would have a nice subtle gradient or something.
                                    # Here we just use the brush of the painter object that's
                                    # passed in to us, which keeps the row highlighting nice
                                    # and consistent.
                                    painter.fillRect(option.rect, painter.brush())
                        
                                # Now that we've painted the background, call star_rating.paint()
                                # to paint the stars.
                                star_rating.paint(painter, option.rect, option.palette)
                        
                            def sizeHint(self, option: widgets.QStyleOptionViewItem, index: core.ModelIndex):
                                """Return the size needed to display the item in a QSize object."""
                                rating = index.data()
                                star_rating = StarRating(rating if rating is not None else 0)
                                return star_rating.sizeHint()
                        
                            # The next 4 methods handle the custom editing that we need to do.
                            # If this were just a display delegate, paint() and sizeHint() would
                            # be all we needed.
                        
                            def createEditor(
                                self,
                                parent: widgets.QWidget,
                                option: widgets.QStyleOptionViewItem,
                                index: core.ModelIndex,
                            ):
                                """Create and return the StarEditor object we'll use to edit the StarRating."""
                                editor = StarEditor(parent)
                                editor.editing_finished.connect(self.commitAndCloseEditor)
                                return editor
                        
                            def setEditorData(self, editor: StarEditor, index: core.ModelIndex):
                                """Set the data to be displayed and edited by our custom editor."""
                                rating = index.data()
                                editor.set_star_rating(rating if rating is not None else 0)
                        
                            def setModelData(
                                self,
                                editor: widgets.QWidget,
                                model: core.QAbstractItemModel,
                                index: core.ModelIndex,
                            ):
                                """Get the data from our custom editor and stuffs it into the model."""
                                model.setData(index, cast("StarEditor", editor).star_rating.star_count)
                        
                            def commitAndCloseEditor(self):
                                editor = self.sender()
                        
                                # The commitData signal must be emitted when we've finished editing
                                # and need to write our changed back to the model.
                                self.commitData.emit(editor)
                                self.closeEditor.emit(editor, self.EndEditHint.NoHint)
                        

                        createEditor(parent: widgets.QWidget, option: widgets.QStyleOptionViewItem, index: core.ModelIndex)

                        Create and return the StarEditor object we'll use to edit the StarRating.

                        Source code in prettyqt/itemdelegates/stardelegate.py
                        def createEditor(
                            self,
                            parent: widgets.QWidget,
                            option: widgets.QStyleOptionViewItem,
                            index: core.ModelIndex,
                        ):
                            """Create and return the StarEditor object we'll use to edit the StarRating."""
                            editor = StarEditor(parent)
                            editor.editing_finished.connect(self.commitAndCloseEditor)
                            return editor
                        

                        setEditorData(editor: StarEditor, index: core.ModelIndex)

                        Set the data to be displayed and edited by our custom editor.

                        Source code in prettyqt/itemdelegates/stardelegate.py
                        def setEditorData(self, editor: StarEditor, index: core.ModelIndex):
                            """Set the data to be displayed and edited by our custom editor."""
                            rating = index.data()
                            editor.set_star_rating(rating if rating is not None else 0)
                        

                        setModelData(editor: widgets.QWidget, model: core.QAbstractItemModel, index: core.ModelIndex)

                        Get the data from our custom editor and stuffs it into the model.

                        Source code in prettyqt/itemdelegates/stardelegate.py
                        def setModelData(
                            self,
                            editor: widgets.QWidget,
                            model: core.QAbstractItemModel,
                            index: core.ModelIndex,
                        ):
                            """Get the data from our custom editor and stuffs it into the model."""
                            model.setData(index, cast("StarEditor", editor).star_rating.star_count)
                        

                        sizeHint(option: widgets.QStyleOptionViewItem, index: core.ModelIndex)

                        Return the size needed to display the item in a QSize object.

                        Source code in prettyqt/itemdelegates/stardelegate.py
                        def sizeHint(self, option: widgets.QStyleOptionViewItem, index: core.ModelIndex):
                            """Return the size needed to display the item in a QSize object."""
                            rating = index.data()
                            star_rating = StarRating(rating if rating is not None else 0)
                            return star_rating.sizeHint()