Skip to main content

QCustomBarChart

QCustomBarChart

Bar chart implementation using the modular architecture.

Qt Designer compatible with property exposure.

At a glance

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

Quick start

from Custom_Widgets.QCustomCharts.QCustomBarChart import QCustomBarChart

widget = QCustomBarChart()
widget.categoriesCsv = "Jan,Feb,Mar,Apr,May,Jun"
widget.seriesCsv = "Revenue=12,19,15,24,22,30;Costs=8,11,9,14,13,17"
_chartPresentation(w, theme, "Revenue vs costs", "Month", "$k")

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.

QCustomBarChart in dark theme

Properties

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

PropertyTypeDefault
showGridboolTrue
gridColorcolor#c8c8c8
showLegendboolTrue
barWidthfloat0.7
stackedboolFalse
showValueLabelsboolTrue
valueLabelsFormatstring{:.1f}
labelsPositionint0
xAxisTitlestringCategories
yAxisTitlestringValues
autoScaleboolTrue
showCrosshairboolTrue
crosshairColorcolor#000000
crosshairWidthfloat1.0
chartTitlestringBar Chart
animationEnabledboolTrue
animationDurationint1000
antialiasingboolTrue
showToolbarboolFalse
tooltipsEnabledboolTrue
tooltipDelayint500
tooltipDurationint5000
themeint0
legendPositionint1
legendFontSizeint8
legendBackgroundVisibleboolFalse
compactModeboolFalse
seriesCsvstring
categoriesCsvstring

Signals

Signal
barClicked(QString,double,QString)
barHovered(QString,double,QString)
chartExportComplete(QString,bool)
legendPositionChanged(QString)
seriesAdded(QString)
seriesRemoved(QString)

Methods

MethodDescription
`addSeries(name: str, values: List[float], categories: List[str]None = None, color: PySide6.QtGui.QColor
appendToSeries(name: str, values: List[float]) -> boolAppend values to an existing series
applyCustomPalette(palette: PySide6.QtGui.QPalette)Apply a custom palette to the chart (for App Theme)
barClicked(...)Bar clicked.
barHovered(...)Bar hovered.
barWidth(*args, **kwargs)Get bar width
chartExportComplete(...)Chart export complete.
clearBarColors(series_name: str = None)Clear the bar colors.
clearData()Clear all chart data (compatibility method)
clearHighlight(series_name: str = None)Clear the highlight.
exportToClipboard()Export chart to clipboard
exportToFile(format: str = None, filename: str = None)Export chart to file
generateExampleData(example_type: str = 'simple')Generate example bar chart data for testing.
getAvailableLegendPositions() -> List[str]Get list of available legend positions
getAvailableThemes() -> List[str]Get list of available theme names
getBarCornerRadius() -> intReturn the bar corner radius.
`getBarSet(series_name: str) -> PySide6.QtCharts.QBarSetNone`
getBarWidth() -> floatGet current bar width
getCategories() -> List[str]Get the current category names
getLabelsPosition() -> strGet current labels position
getLegendAlignment() -> PySide6.QtCore.Qt.AlignmentFlagGet current legend alignment
getLegendFontSize() -> intGet legend font size
getSeriesData(name: str) -> List[Tuple[float, float]]Get data for a specific series (overrides base method)
getSeriesNames() -> List[str]Get list of all series names (overrides base method)
getShowValueLabels() -> boolCheck if value labels are shown
getValueLabelsFormat() -> strGet value labels format string
getYAxisRange() -> Tuple[float, float]Get Y axis range
gridColor(*args, **kwargs)Get grid color
hideCrosshair()Manually hide crosshair
hideTooltip()Manually hide tooltip
highlightBar(category: str, series_name: str, highlight: bool = True)Highlight a specific bar
highlightIndex(index: int, color=None, series_name: str = None)Accent a single bar (by category index). color defaults to a
isStacked() -> boolCheck if bars are stacked
labelsPosition(*args, **kwargs)Bar labels position (int; see QCustomChartEnums.BarLabelsPosition).
legendPositionChanged(...)Legend position changed.
printChart()Print chart
refreshTheme()Refresh the current theme (useful when app palette changes)
removeSeries(name: str) -> boolRemove a series from the chart
seriesAdded(...)Series added.
seriesRemoved(...)Series removed.
setBarColors(colors, series_name: str = None)Give each bar its own colour. colors is a list parallel to the
setBarCornerRadius(radius: int)Round the top corners of bars (px). 0 restores native square bars.
setBarWidth(width: float)Set relative bar width (0.0 to 1.0)
setCategories(categories: List[str])Set the category names for the X axis
setChartTitle(title: str)Set chart title (compatibility method)
setCrosshairColor(color: PySide6.QtGui.QColor)Set crosshair line color
setCrosshairStyle(style: PySide6.QtCore.Qt.PenStyle)Set crosshair line style
setCrosshairWidth(width: float)Set crosshair line width
setGridLineAlpha(alpha: int)Set just the grid line opacity (0-255), keeping the current hue.
`setGridLineColor(color, alpha: intNone = None)`
setLabelsPosition(position: str)Set position of value labels
setLegendAlignment(alignment: PySide6.QtCore.Qt.AlignmentFlag)Directly set legend alignment
setLegendBackgroundVisible(visible: bool)Set legend background visibility
setLegendFontSize(size: int)Set legend font size
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)
setShowValueLabels(show: bool)Set whether value labels are shown on bars
setStacked(stacked: bool)Set whether bars are stacked
setValueLabelsFormat(format_str: str)Set format string for value labels
setXAxisTitle(title: str)Set X axis title
setYAxisRange(min_val: float, max_val: float)Set Y axis range
setYAxisTitle(title: str)Set Y axis title
showCrosshairAt(x: float, y: float)Manually show crosshair at specific coordinates
showGrid(*args, **kwargs)Get grid visibility
showLegend(*args, **kwargs)Get legend visibility
showTooltipAt(x: float, y: float, series_name: str, title: str = None, description: str = None)Manually show tooltip at specific coordinates
showValueLabels(*args, **kwargs)Get value labels visibility
stacked(*args, **kwargs)Get stacked state
updateChart()Update the chart display based on current data
updateSeriesData(name: str, values: List[float]) -> boolUpdate data for an existing series
valueLabelsFormat(*args, **kwargs)Get value labels format

Theming

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

See Design tokens.

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