Skip to main content

QCustomQLabel

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

TierFree (GPLv3)
Importfrom Custom_Widgets.QCustomQLabel import QCustomQLabel
Qt DesignerYes — 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.

QCustomQLabel in dark theme

Properties

Every property below is settable in code and in Qt Designer.

PropertyTypeDefault
frameShapeQFrame::Shape
frameShadowQFrame::Shadow
lineWidthint
midLineWidthint
frameWidthint
frameRectQRect
textstring
textFormatQt::TextFormat
pixmapQPixmap
scaledContentsbool
alignmentQFlags<Qt::AlignmentFlag>
wordWrapbool
marginint
indentint
openExternalLinksbool
textInteractionFlagsQFlags<Qt::TextInteractionFlag>
hasSelectedTextbool
selectedTextstring
iconColorcolor
iconSizeint0
imageSourcestring
imageCornerRadiusint0

Methods

MethodDescription
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.

AnalogGaugeWidget · QCustomAgendaList · QCustomAlert · QCustomAvatar · QCustomAvatarGroup · QCustomBadge · QCustomCard · QCustomChip