Skip to main content

QCustomPieChart

QCustomPieChart

Pie chart implementation using the modular architecture.

Qt Designer compatible with property exposure.

At a glance

TierFree (GPLv3)
Importfrom Custom_Widgets.QCustomCharts.QCustomPieChart import QCustomPieChart
Qt DesignerYes — drag it from the palette

Quick start

from Custom_Widgets.QCustomCharts.QCustomPieChart import QCustomPieChart

widget = QCustomPieChart()
widget.categoriesCsv = "Direct,Search,Social,Referral"
widget.seriesCsv = "Sessions=42,28,18,12"
_chartPresentation(w, theme, "Traffic by source", None, None)

That is the exact code behind the screenshot above.

Dark theme

Colours come from the design tokens, so the widget follows the app theme with no extra work.

QCustomPieChart in dark theme

Properties

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

PropertyTypeDefault
showPercentagesboolTrue
showValuesboolTrue
showLegendboolTrue
showLabelsboolTrue
labelsPositionint0
showPercentLabelsboolFalse
hatchCsvstring
hatchPatternstringbdiag
explosionDistancefloat0.1
holeSizefloat0.0
startAnglefloat0.0
endAnglefloat360.0
semicircleEnabledboolFalse
pieAngularSpanfloat180.0
semicircleOrientationstringright
gradientFillboolTrue
gradientTypestringradial
borderWidthfloat2.0
borderColorcolor#ffffff
legendMarkerBorderWidthfloat1.0
explodeOnHoverboolTrue
hoverExplosionDistancefloat0.15
chartTitlestringPie Chart
animationEnabledboolTrue
animationDurationint1000
antialiasingboolTrue
showToolbarboolFalse
tooltipsEnabledboolTrue
tooltipDelayint500
tooltipDurationint5000
themeint0
legendPositionint1
legendFontSizeint8
legendBackgroundVisibleboolFalse
compactModeboolFalse
seriesCsvstring
categoriesCsvstring

Signals

Signal
chartExportComplete(QString,bool)
legendPositionChanged(QString)
seriesAdded(QString)
seriesRemoved(QString)
sliceClicked(QString,double)
sliceExploded(QString,bool)
sliceHovered(QString,double)

Methods

MethodDescription
`addSeries(name: str, data: List[Tuple[str, float]], color: PySide6.QtGui.QColorNone = None, visible: bool = True, colors: List
addSlice(series_name: str, slice_name: str, value: float) -> boolAdd a slice to an existing series
applyCustomPalette(palette: PySide6.QtGui.QPalette)Apply a custom palette to the chart (for App Theme)
areLabelsVisible() -> boolCheck if labels are visible
borderColor(*args, **kwargs)Get border color
borderWidth(*args, **kwargs)Get border width
chartExportComplete(...)Chart export complete.
clearAllData()Clear all chart data
clearData()Clear all chart data (compatibility method)
endAngle(*args, **kwargs)Get end angle
explodeAllSlices(explode: bool = True)Explode or un-explode all slices
explodeOnHover(*args, **kwargs)Get explode on hover state
explodeSlice(slice_name: str, explode: bool = True)Explode or un-explode a slice
explosionDistance(*args, **kwargs)Get explosion distance
exportToClipboard()Export chart to clipboard
exportToFile(format: str = None, filename: str = None)Export chart to file
generateExampleData(example_type: str = 'categories')Generate example data for testing.
getAvailableLegendPositions() -> List[str]Get list of available legend positions
getAvailableThemes() -> List[str]Get list of available theme names
getBorderColor() -> PySide6.QtGui.QColorGet border color
getBorderWidth() -> floatGet border width
getEndAngle() -> floatGet the ending angle in degrees
getExplosionDistance() -> floatGet the explosion distance factor
getGradientType() -> strGet gradient type
getHoleSize() -> floatGet the hole size for donut chart
getHoverExplosionDistance() -> floatGet the explosion distance factor for hover
getLabelsPosition() -> strGet labels position
getLegendAlignment() -> PySide6.QtCore.Qt.AlignmentFlagGet current legend alignment
getLegendFontSize() -> intGet legend font size
getLegendMarkerBorderWidth() -> floatGet the border width for legend markers
getPercentage(series_name: str, slice_name: str) -> floatGet the percentage of a slice
getPieAngularSpan() -> floatGet the angular span of the pie in degrees
getSemicircleOrientation() -> strGet the orientation of the semicircle
getSeriesData(name: str) -> List[Tuple[str, float]]Get data for a specific series (pie chart version)
getSeriesNames() -> List[str]Get list of all series names (overrides base method)
getSliceNames(series_name: str) -> List[str]Get list of slice names for a series
`getSliceValue(series_name: str, slice_name: str) -> floatNone`
getStartAngle() -> floatGet the starting angle in degrees
getTotalValue(series_name: str) -> floatGet the total value of all slices in a series
gradientFill(*args, **kwargs)Get gradient fill state
gradientType(*args, **kwargs)Get gradient type
hatchCsv(*args, **kwargs)Hatch csv.
hatchPattern(*args, **kwargs)Hatch pattern.
hideTooltip()Manually hide tooltip
holeSize(*args, **kwargs)Get hole size
hoverExplosionDistance(*args, **kwargs)Get hover explosion distance
isExplodeOnHoverEnabled() -> boolCheck if explode on hover is enabled
isGradientFillEnabled() -> boolCheck if gradient fill is enabled
isSemicircleEnabled() -> boolCheck if semicircle mode is enabled
isSliceExploded(slice_name: str) -> boolCheck if a slice is exploded
labelsPosition(*args, **kwargs)Labels position (int; see QCustomChartEnums.LabelsPosition).
legendMarkerBorderWidth(*args, **kwargs)Get legend marker border width
legendPositionChanged(...)Legend position changed.
pieAngularSpan(*args, **kwargs)Get pie angular span
printChart()Print chart
refreshTheme()Refresh the current theme (useful when app palette changes)
removeSeries(name: str) -> boolRemove a series from the chart
removeSlice(series_name: str, slice_name: str) -> boolRemove a slice from a series
semicircleEnabled(*args, **kwargs)Get semicircle enabled state
semicircleOrientation(*args, **kwargs)Get semicircle orientation
seriesAdded(...)Series added.
seriesRemoved(...)Series removed.
setBorderColor(color: PySide6.QtGui.QColor)Set border color
setBorderWidth(width: float)Set border width
setChartTitle(title: str)Set chart title (compatibility method)
setEndAngle(angle: float)Set the ending angle in degrees
setExplodeOnHover(enabled: bool)Enable or disable explode on hover
setExplosionDistance(distance: float)Set the explosion distance factor (0.0 to 1.0)
setGradientFill(enabled: bool)Enable or disable gradient fill
setGradientType(gradient_type: str)Set gradient type: 'radial' or 'conical'
setHatchIndices(indices)Slice indices (within the series) rendered with a hatch/pattern fill.
setHatchPattern(name)Set the hatch pattern.
setHoleSize(size: float)Set the hole size for donut chart (0.0 to 0.9)
setHoverExplosionDistance(distance: float)Set the explosion distance factor for hover (0.0 to 1.0)
setLabelsPosition(position: str)Set labels position: 'outside', 'inside', or 'callout'
setLabelsVisible(visible: bool)Set labels visibility
setLegendAlignment(alignment: PySide6.QtCore.Qt.AlignmentFlag)Directly set legend alignment
setLegendBackgroundVisible(visible: bool)Set legend background visibility
setLegendFontSize(size: int)Set legend font size
setLegendMarkerBorderWidth(width: float)Set the border width for legend markers
setPieAngularSpan(span: float)Set the angular span of the pie in degrees
setSemicircleEnabled(enabled: bool)Enable or disable semicircle/half pie display
setSemicircleOrientation(orientation: str)Set the orientation of the semicircle
setSeriesColor(name: str, color: PySide6.QtGui.QColor)Set color for a specific series (overrides base method)
setSeriesVisibility(name: str, visible: bool)Set visibility for a specific series (overrides base method)
setShowPercentLabels(on)Convenience: show a % label inside each slice (like QCustomDonut).
setShowPercentages(show: bool)Set whether to show percentages in labels
setShowValues(show: bool)Set whether to show values in labels
setSliceColors(series_name: str, colors: List) -> boolSet per-slice colours for a series and redraw.
setStartAngle(angle: float)Set the starting angle in degrees
showLabels(*args, **kwargs)Get labels visibility
showLegend(*args, **kwargs)Get legend visibility
showPercentLabels(*args, **kwargs)True when slices show a % label inside (convenience toggle).
showPercentages(*args, **kwargs)Get show percentages state
showTooltipAt(x: float, y: float, slice_name: str, title: str = None, description: str = None)Manually show tooltip at specific coordinates
showValues(*args, **kwargs)Get show values state
sliceClicked(...)Slice clicked.
sliceExploded(...)Slice exploded.
sliceHovered(...)Slice hovered.
startAngle(*args, **kwargs)Get start angle
toggleSliceExplosion(slice_name: str)Toggle explosion state of a slice
updateChart()Update the chart display based on current data
updateSeriesData(name: str, data: List[Tuple[str, float]]) -> boolUpdate data for an existing series
updateSliceValue(series_name: str, slice_name: str, new_value: float) -> boolUpdate the value of a slice

Theming

Colours come from the design tokens, so they follow the active theme. Roles used: surface, on-surface, outline, accent.

See Design tokens.

QCustomAreaChart · QCustomBarChart · QCustomBeeswarm · QCustomBubbleChart · QCustomCandlestickChart · QCustomCompass · QCustomCompassDial · QCustomDivergingBarChart