Class: QgsHistogramWidget

Graphical histogram for displaying distributions of field values.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsHistogramWidget

Base classes

QWidget

QObject

QPaintDevice

Subclasses

QgsGraduatedHistogramWidget

Graphical histogram for displaying distribution of field values and editing range breaks for a QgsGraduatedSymbolRenderer renderer.

Methods

brush

Returns the brush used when drawing histogram bars.

graduatedRanges

Returns the graduated ranges associated with the histogram.

layer

Returns the layer currently associated with the widget.

pen

Returns the pen used when drawing histogram bars.

refresh

Redraws the histogram.

refreshValues

Refreshes the values for the histogram by fetching them from the layer.

setBrush

Sets the brush used for drawing histogram bars.

setGraduatedRanges

Sets the graduated ranges associated with the histogram.

setLayer

Sets the vector layer associated with the histogram.

setPen

Sets the pen to use when drawing histogram bars.

setSourceFieldExp

Sets the source field or expression to use for values in the histogram.

setXAxisTitle

Sets the title for the histogram's x-axis.

setYAxisTitle

Sets the title for the histogram's y-axis.

sourceFieldExp

Returns the source field name or expression used to calculate values displayed in the histogram.

xAxisTitle

Returns the title for the histogram's x-axis.

yAxisTitle

Returns the title for the histogram's y-axis.

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsHistogramWidget. See the FAQ for more details.

drawHistogram

Updates and redraws the histogram.

class qgis.gui.QgsHistogramWidget[source]

Bases: QWidget

__init__(parent: QWidget | None = None, layer: QgsVectorLayer | None = None, fieldOrExp: str | None = '')

QgsHistogramWidget constructor. If layer and fieldOrExp are specified then the histogram will be initially populated with the corresponding values.

Parameters:
  • parent (Optional[QWidget] = None) – parent widget

  • layer (Optional[QgsVectorLayer] = None) – source vector layer

  • fieldOrExp (Optional[str] = '') – field name or expression string

brush(self) QBrush[source]

Returns the brush used when drawing histogram bars.

See also

setBrush()

See also

pen()

Return type:

QBrush

virtual drawHistogram(self)[source]

Updates and redraws the histogram.

graduatedRanges(self) List[QgsRendererRange][source]

Returns the graduated ranges associated with the histogram. If set, the ranges will be used to color the histogram bars and for showing vertical dividers at the histogram breaks.

Return type:

List[QgsRendererRange]

Returns:

graduated range list

layer(self) QgsVectorLayer | None[source]

Returns the layer currently associated with the widget.

See also

setLayer()

See also

sourceFieldExp()

Return type:

Optional[QgsVectorLayer]

pen(self) QPen[source]

Returns the pen used when drawing histogram bars.

See also

setPen()

See also

brush()

Return type:

QPen

refresh(self)[source]

Redraws the histogram. Calling this slot does not update the values for the histogram, use refreshValues() to do this.

refreshValues(self)[source]

Refreshes the values for the histogram by fetching them from the layer.

setBrush(self, brush: QBrush | QColor | Qt.GlobalColor | QGradient)[source]

Sets the brush used for drawing histogram bars. If ranges have been set using setGraduatedRanges() then the pen and brush will have no effect.

Parameters:

brush (Union[QBrush, Union[QColor, Qt.GlobalColor], QGradient]) – histogram brush

See also

brush()

See also

setPen()

setGraduatedRanges(self, ranges: Iterable[QgsRendererRange])[source]

Sets the graduated ranges associated with the histogram. If set, the ranges will be used to color the histogram bars and for showing vertical dividers at the histogram breaks.

Parameters:

ranges (Iterable[QgsRendererRange]) – graduated range list

setLayer(self, layer: QgsVectorLayer | None)[source]

Sets the vector layer associated with the histogram.

Parameters:

layer (Optional[QgsVectorLayer]) – source vector layer

setPen(self, pen: QPen | QColor | Qt.GlobalColor)[source]

Sets the pen to use when drawing histogram bars. If set to Qt.NoPen then the pen will be automatically calculated. If ranges have been set using setGraduatedRanges() then the pen and brush will have no effect.

Parameters:

pen (Union[QPen, Union[QColor, Qt.GlobalColor]]) – histogram pen

See also

pen()

See also

setBrush()

setSourceFieldExp(self, fieldOrExp: str | None)[source]

Sets the source field or expression to use for values in the histogram.

Parameters:

fieldOrExp (Optional[str]) – field name or expression string

See also

setLayer()

setXAxisTitle(self, title: str | None)[source]

Sets the title for the histogram’s x-axis.

Parameters:

title (Optional[str]) – x-axis title, or empty string to remove title

See also

xAxisTitle()

See also

setYAxisTitle()

setYAxisTitle(self, title: str | None)[source]

Sets the title for the histogram’s y-axis.

Parameters:

title (Optional[str]) – y-axis title, or empty string to remove title

See also

yAxisTitle()

See also

setXAxisTitle()

sourceFieldExp(self) str[source]

Returns the source field name or expression used to calculate values displayed in the histogram.

See also

layer()

Return type:

str

xAxisTitle(self) str[source]

Returns the title for the histogram’s x-axis.

See also

setXAxisTitle()

See also

yAxisTitle()

Return type:

str

yAxisTitle(self) str[source]

Returns the title for the histogram’s y-axis.

See also

setYAxisTitle()

See also

xAxisTitle()

Return type:

str