RenderLinkDelegate
Base classes
⋔ Inheritance diagram
graph TD
3584650895["itemdelegates.RenderLinkDelegate"]
4109708588["widgets.StyledItemDelegate"]
3153451512["widgets.AbstractItemDelegateMixin"]
3227531497["core.ObjectMixin"]
2751680898["builtins.object"]
3599391368["QtWidgets.QStyledItemDelegate"]
475576970["QtWidgets.QAbstractItemDelegate"]
3984060476["QtCore.QObject"]
37984305["Shiboken.Object"]
4109708588 --> 3584650895
3153451512 --> 4109708588
3227531497 --> 3153451512
2751680898 --> 3227531497
2751680898 --> 3153451512
3599391368 --> 4109708588
475576970 --> 3599391368
3984060476 --> 475576970
37984305 --> 3984060476
2751680898 --> 37984305
🛈 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()
try:
if option.state & 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)
finally:
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
and b_rect.contains(event.position())
):
text = index.data()
gui.DesktopServices.open_url(text)
return True
return False
|
:fa-brands-github: Show source on GitHub