QgsHistogramWidget class

Graphical histogram for displaying distributions of field values.

Derived classes

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

Constructors, destructors, conversion operators

QgsHistogramWidget(QWidget* parent = nullptr, QgsVectorLayer* layer = nullptr, const QString& fieldOrExp = QString())
QgsHistogramWidget constructor.

Public functions

auto brush() const -> QBrush
Returns the brush used when drawing histogram bars.
auto graduatedRanges() const -> QgsRangeList
Returns the graduated ranges associated with the histogram.
auto layer() -> QgsVectorLayer*
Returns the layer currently associated with the widget.
auto pen() const -> QPen
Returns the pen used when drawing histogram bars.
void setBrush(const QBrush& brush)
Sets the brush used for drawing histogram bars.
void setGraduatedRanges(const QgsRangeList& ranges)
Sets the graduated ranges associated with the histogram.
void setPen(const QPen& pen)
Sets the pen to use when drawing histogram bars.
void setXAxisTitle(const QString& title)
Sets the title for the histogram's x-axis.
void setYAxisTitle(const QString& title)
Sets the title for the histogram's y-axis.
auto sourceFieldExp() const -> QString
Returns the source field name or expression used to calculate values displayed in the histogram.
auto xAxisTitle() const -> QString
Returns the title for the histogram's x-axis.
auto yAxisTitle() const -> QString
Returns the title for the histogram's y-axis.

Public slots

void refresh()
Redraws the histogram.
void refreshValues()
Refreshes the values for the histogram by fetching them from the layer.
void setLayer(QgsVectorLayer* layer)
Sets the vector layer associated with the histogram.
void setSourceFieldExp(const QString& fieldOrExp)
Sets the source field or expression to use for values in the histogram.

Protected functions

void drawHistogram() virtual
Updates and redraws the histogram.

Function documentation

QgsHistogramWidget::QgsHistogramWidget(QWidget* parent = nullptr, QgsVectorLayer* layer = nullptr, const QString& fieldOrExp = QString())

QgsHistogramWidget constructor.

Parameters
parent parent widget
layer source vector layer
fieldOrExp field name or expression string

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

QBrush QgsHistogramWidget::brush() const

Returns the brush used when drawing histogram bars.

QgsRangeList QgsHistogramWidget::graduatedRanges() const

Returns the graduated ranges associated with the histogram.

Returns graduated range list

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

QgsVectorLayer* QgsHistogramWidget::layer()

Returns the layer currently associated with the widget.

QPen QgsHistogramWidget::pen() const

Returns the pen used when drawing histogram bars.

void QgsHistogramWidget::setBrush(const QBrush& brush)

Sets the brush used for drawing histogram bars.

Parameters
brush histogram brush

If ranges have been set using setGraduatedRanges() then the pen and brush will have no effect.

void QgsHistogramWidget::setGraduatedRanges(const QgsRangeList& ranges)

Sets the graduated ranges associated with the histogram.

Parameters
ranges graduated range list

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

void QgsHistogramWidget::setPen(const QPen& pen)

Sets the pen to use when drawing histogram bars.

Parameters
pen histogram pen

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.

void QgsHistogramWidget::setXAxisTitle(const QString& title)

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

Parameters
title x-axis title, or empty string to remove title

void QgsHistogramWidget::setYAxisTitle(const QString& title)

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

Parameters
title y-axis title, or empty string to remove title

QString QgsHistogramWidget::sourceFieldExp() const

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

QString QgsHistogramWidget::xAxisTitle() const

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

QString QgsHistogramWidget::yAxisTitle() const

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

void QgsHistogramWidget::refresh() public slot

Redraws the histogram.

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

void QgsHistogramWidget::setLayer(QgsVectorLayer* layer) public slot

Sets the vector layer associated with the histogram.

Parameters
layer source vector layer

void QgsHistogramWidget::setSourceFieldExp(const QString& fieldOrExp) public slot

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

Parameters
fieldOrExp field name or expression string