delegates
_delegates
¶
Custom item delegates for tree/list views.
Classes:
| Name | Description |
|---|---|
FXColorLabelDelegate |
A custom delegate to paint items with specific colors and icons based |
FXItemDelegate |
Minimal delegate that enables QIcon mode switching on hover/selection. |
FXThumbnailDelegate |
Custom item delegate for showing thumbnails in tree/list views. |
Classes¶
FXColorLabelDelegate
¶
FXColorLabelDelegate(
colors_icons: Dict[str, Tuple[QColor, QColor, QColor, QIcon, bool]],
parent: Optional[QWidget] = None,
margin_left: int = 2,
margin_top: Optional[int] = None,
margin_bottom: Optional[int] = None,
)
Bases: FXThemeAware, QStyledItemDelegate
flowchart TD
fxgui.fxwidgets._delegates.FXColorLabelDelegate[FXColorLabelDelegate]
fxgui.fxstyle.FXThemeAware[FXThemeAware]
fxgui.fxstyle.FXThemeAware --> fxgui.fxwidgets._delegates.FXColorLabelDelegate
click fxgui.fxwidgets._delegates.FXColorLabelDelegate href "" "fxgui.fxwidgets._delegates.FXColorLabelDelegate"
click fxgui.fxstyle.FXThemeAware href "" "fxgui.fxstyle.FXThemeAware"
A custom delegate to paint items with specific colors and icons based on their text content.
Note
This delegate automatically refreshes when the theme changes, ensuring that default colors (for items without explicit color mappings) stay in sync with the current theme.
Initializes the delegate with a dictionary of colors and icons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Dict[str, Tuple[QColor, QColor, QColor, QIcon, bool]]
|
A dictionary where keys are text patterns and values are tuples containing background color, border color, text/icon color, icon, and a boolean indicating if the icon should be colored. |
required |
|
Optional[QWidget]
|
The parent object. |
None
|
|
int
|
The left margin for the text and icon. Defaults to 2. |
2
|
|
Optional[int]
|
The top margin for the text and icon. Defaults to
|
None
|
|
Optional[int]
|
The bottom margin for the text and icon. Defaults to
|
None
|
Methods:
| Name | Description |
|---|---|
paint |
Paints the item with the specified colors and icons. |
sizeHint |
Provides the size hint for the item. |
FXItemDelegate
¶
Bases: QStyledItemDelegate
flowchart TD
fxgui.fxwidgets._delegates.FXItemDelegate[FXItemDelegate]
click fxgui.fxwidgets._delegates.FXItemDelegate href "" "fxgui.fxwidgets._delegates.FXItemDelegate"
Minimal delegate that enables QIcon mode switching on hover/selection.
Qt's default item view painting only uses QIcon.Selected for selected items. This delegate adds QIcon.Active support for hover states, making icons change color when items are hovered.
This is a drop-in replacement for QStyledItemDelegate with no layout changes. Apply it to any QListView, QTreeView, or QTableView for icon color switching.
Examples:
>>> from fxgui import fxwidgets
>>> list_widget = QListWidget()
>>> list_widget.setItemDelegate(fxwidgets.FXItemDelegate())
FXThumbnailDelegate
¶
Bases: FXThemeAware, QStyledItemDelegate
flowchart TD
fxgui.fxwidgets._delegates.FXThumbnailDelegate[FXThumbnailDelegate]
fxgui.fxstyle.FXThemeAware[FXThemeAware]
fxgui.fxstyle.FXThemeAware --> fxgui.fxwidgets._delegates.FXThumbnailDelegate
click fxgui.fxwidgets._delegates.FXThumbnailDelegate href "" "fxgui.fxwidgets._delegates.FXThumbnailDelegate"
click fxgui.fxstyle.FXThemeAware href "" "fxgui.fxstyle.FXThemeAware"
Custom item delegate for showing thumbnails in tree/list views.
This delegate displays items with thumbnails, titles, descriptions, and status indicators. It supports Markdown formatting in descriptions and tooltips. Additionally, it supports custom background colors via Qt.BackgroundRole with rounded corners and borders for visual hierarchy.
Note
Store data in items using the following roles:
- Qt.BackgroundRole (QColor/QBrush): Custom background color
with rounded corners and border.
- Qt.DecorationRole (QIcon): Icon for items without thumbnails.
- Qt.UserRole + 1 (bool): Whether to show the thumbnail.
- Qt.UserRole + 2 (str): Path to the thumbnail image.
- Qt.UserRole + 3 (str): Description text (supports Markdown).
- Qt.UserRole + 4 (QColor): Status dot indicator color.
- Qt.UserRole + 5 (QColor): Status label background color.
- Qt.UserRole + 6 (str): Status label text.
- Qt.UserRole + 7 (bool): Whether to show the status dot.
- Qt.UserRole + 8 (bool): Whether to show the status label.
- Qt.UserRole + 9 (QIcon): Status label icon (displayed before text).
Properties
show_thumbnail: Whether to show thumbnails globally. show_status_dot: Whether to show the status dot indicator globally. show_status_label: Whether to show the status label globally.
Note
Global properties and per-item roles work together: - An element is shown only if BOTH global property is True AND per-item role is True (or None/unset). - Setting per-item role to False hides that element for that item.
Note
When using custom backgrounds (Qt.BackgroundRole), call
FXThumbnailDelegate.apply_transparent_selection(view) to disable the
native Qt selection/hover highlighting, allowing the delegate's custom
highlighting to be visible.
Examples:
>>> from fxgui import fxwidgets
>>> from qtpy.QtWidgets import QTreeWidget, QTreeWidgetItem
>>> from qtpy.QtCore import Qt
>>> from qtpy.QtGui import QColor
>>>
>>> tree = QTreeWidget()
>>> delegate = fxwidgets.FXThumbnailDelegate()
>>> delegate.show_thumbnail = True
>>> delegate.show_status_dot = True
>>> delegate.show_status_label = True
>>> tree.setItemDelegate(delegate)
>>>
>>> item = QTreeWidgetItem(tree, ["My Item"])
>>> item.setData(0, fxwidgets.FXThumbnailDelegate.THUMBNAIL_VISIBLE_ROLE, True)
>>> item.setData(0, fxwidgets.FXThumbnailDelegate.THUMBNAIL_PATH_ROLE, "/path/to/image.png")
>>> item.setData(0, fxwidgets.FXThumbnailDelegate.DESCRIPTION_ROLE, "**Bold** description")
>>> item.setData(0, fxwidgets.FXThumbnailDelegate.STATUS_DOT_COLOR_ROLE, QColor("green"))
>>> # Hide status dot for this specific item
>>> item.setData(0, fxwidgets.FXThumbnailDelegate.STATUS_DOT_VISIBLE_ROLE, False)
>>> # Custom background color with rounded corners and border
>>> item.setBackground(0, QColor("#252424"))
Initialize the thumbnail delegate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Optional[QWidget]
|
The parent widget. |
None
|
Methods:
| Name | Description |
|---|---|
apply_transparent_selection |
Apply transparent selection stylesheet to a tree view widget. |
helpEvent |
Provide Markdown-formatted tooltips. |
markdown_to_html |
Convert Markdown text to HTML. |
markdown_to_plain_text |
Convert Markdown text to plain text by removing formatting. |
paint |
Paint the item with custom background, border, and hover/selection. |
sizeHint |
Return the size hint for the item at the given index. |
Attributes:
| Name | Type | Description |
|---|---|---|
show_status_dot |
bool
|
Whether the status dot is shown. |
show_status_label |
bool
|
Whether the status label is shown. |
show_thumbnail |
bool
|
Whether thumbnails are shown globally. |
Attributes¶
show_thumbnail
property
writable
¶
show_thumbnail: bool
Whether thumbnails are shown globally.
Individual items can override via THUMBNAIL_VISIBLE_ROLE.
Functions¶
apply_transparent_selection
staticmethod
¶
apply_transparent_selection(view: QWidget) -> None
Apply transparent selection stylesheet to a tree view widget.
This method disables the default Qt selection/hover backgrounds by applying a comprehensive stylesheet directly to the widget. The delegate handles all selection and hover highlighting itself.
Call this on QTreeView/QTreeWidget instances that use custom backgrounds with FXThumbnailDelegate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view
¶ |
QWidget
|
The tree view widget to apply transparent selection to. |
required |
helpEvent
¶
helpEvent(
event: QHelpEvent,
view: QAbstractItemView,
option: QStyleOptionViewItem,
index: QModelIndex,
) -> bool
Provide Markdown-formatted tooltips.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
¶ |
QHelpEvent
|
The help event. |
required |
view
¶ |
QAbstractItemView
|
The view widget. |
required |
option
¶ |
QStyleOptionViewItem
|
Style options. |
required |
index
¶ |
QModelIndex
|
The model index. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the event was handled. |
markdown_to_html
staticmethod
¶
markdown_to_plain_text
staticmethod
¶
paint
¶
Paint the item with custom background, border, and hover/selection.
This method handles all painting consistently across all items and columns, ensuring hover and selection highlighting looks the same everywhere. It supports custom background colors via Qt.BackgroundRole with rounded corners and borders.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
painter
¶ |
QPainter
|
The painter to use for drawing. |
required |
option
¶ |
QStyleOptionViewItem
|
The style options for the item. |
required |
index
¶ |
QModelIndex
|
The model index of the item. |
required |