QCustomQLabel
A QLabel that can show an SVG ICON recoloured from QSS.
The icon FILE is set the normal way (a QLabel pixmap — in the .ui or from
QSS with the path variable), and the label TINTS that pixmap to iconColor,
so a decorative label icon tracks ANY token (a brand-orange logo, a muted
glyph) with no Python and recolours on a theme switch:
QCustomQLabel#logoIcon { qproperty-pixmap: url($PATH_RESOURCES+'feather/activity.svg'); qproperty-iconColor: $logo; } QCustomQLabel#searchIcon { qproperty-pixmap: url($PATH_RESOURCES+'feather/search.svg'); qproperty-iconColor: $muted; }
(Buttons use qproperty-icon; a QLabel has no icon property, so the file goes
through qproperty-pixmap.) It renders at iconSize px, or at the widget
size when iconSize is 0 (default). Leave iconColor unset and the pixmap shows
as-is (an ordinary QLabel).
At a glance
| Tier | Free (GPLv3) |
| Import | from Custom_Widgets.QCustomQLabel import QCustomQLabel |
| Qt Designer | Yes — drag it from the palette |
Quick start
from Custom_Widgets.QCustomQLabel import QCustomQLabel
widget = QCustomQLabel()
Dark theme
Colours come from the design tokens, so the widget follows the app theme with no extra work.
Properties
Every property below is settable in code and in Qt Designer.
| Property | Type | Default |
|---|---|---|
frameShape | QFrame::Shape | — |
frameShadow | QFrame::Shadow | — |
lineWidth | int | — |
midLineWidth | int | — |
frameWidth | int | — |
frameRect | QRect | — |
text | string | — |
textFormat | Qt::TextFormat | — |
pixmap | QPixmap | — |
scaledContents | bool | — |
alignment | QFlags<Qt::AlignmentFlag> | — |
wordWrap | bool | — |
margin | int | — |
indent | int | — |
openExternalLinks | bool | — |
textInteractionFlags | QFlags<Qt::TextInteractionFlag> | — |
hasSelectedText | bool | — |
selectedText | string | — |
iconColor | color | — |
iconSize | int | 0 |
imageSource | string | — |
imageCornerRadius | int | 0 |
Methods
| Method | Description |
|---|---|
iconColor(*args, **kwargs) | Icon color. |
iconSize(*args, **kwargs) | Icon size. |
imageCornerRadius(*args, **kwargs) | Image corner radius. |
imageSource(*args, **kwargs) | Image source. |
setImageSource(source) | Set the image source. |
Theming
Colours come from the design tokens, so they follow the active theme. Roles used: on-surface.
See Design tokens.
Related
AnalogGaugeWidget · QCustomAgendaList · QCustomAlert · QCustomAvatar · QCustomAvatarGroup · QCustomBadge · QCustomCard · QCustomChip