Skip to content

RenderLinkDelegate

Qt Base Class: QStyledItemDelegate

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

Base classes

Name Children Inherits
StyledItemDelegate
prettyqt.widgets.styleditemdelegate

⋔ Inheritance diagram

graph TD
  1473367012080["itemdelegates.RenderLinkDelegate"]
  1473296354464["widgets.StyledItemDelegate"]
  1473296344704["widgets.AbstractItemDelegateMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473293727280["QtWidgets.QStyledItemDelegate"]
  1473293758512["QtWidgets.QAbstractItemDelegate"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473296354464 --> 1473367012080
  1473296344704 --> 1473296354464
  1473299815024 --> 1473296344704
  140713234304496 --> 1473299815024
  1473293727280 --> 1473296354464
  1473293758512 --> 1473293727280
  1473288842240 --> 1473293758512
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208

🛈 DocStrings

Bases: StyledItemDelegate

Source code in prettyqt\itemdelegates\renderlinkdelegate.py
class RenderLinkDelegate(widgets.StyledItemDelegate):
    ID = "render_link"

    def paint(
        self,
        painter: gui.QPainter,
        option: widgets.QStyleOptionViewItem,
        index: core.ModelIndex,
    ):
        text = index.data()
        if not text:
            return
        option = widgets.StyleOptionViewItem(option)
        self.initStyleOption(option, index)
        painter.save()

        if option.state and widgets.Style.StateFlag.State_MouseOver:
            font = option.font
            font.setUnderline(True)
            painter.setFont(font)
            painter.setPen(option.palette.link().color())
        rect = option.rect.toRectF()
        painter.drawText(rect, constants.ALIGN_CENTER_LEFT, text)
        painter.restore()

    def editorEvent(
        self,
        event,
        model: core.QAbstractItemModel,
        option: widgets.QStyleOptionViewItem,
        index: core.ModelIndex,
    ):
        text = index.data()
        font = index.data(constants.FONT_ROLE) or gui.GuiApplication.font()
        # alignment = index.data(constants.ALIGNMENT_ROLE)
        fm = gui.FontMetricsF(font)
        rect = option.rect.toRectF()
        b_rect = fm.get_bounding_rect(rect, constants.ALIGN_CENTER_LEFT, text)
        if (
            event.type() == core.QEvent.Type.MouseButtonPress
            and event.button() == constants.MouseButton.LeftButton  # type: ignore
            and b_rect.contains(event.position())  # type: ignore
        ):
            text = index.data()
            gui.DesktopServices.open_url(text)
            return True
        return False

⌗ Property table

Qt Property Type Doc
objectName QString

Delegate ID: render_link