- Qt 6.10
- Qt Graphs
- C++ Classes
- QtGraphsWidgets
- Q3DBarsWidgetItem
- Qt Graphs | Commercial or GPLv3

# Q3DBarsWidgetItem Class

The Q3DBarsWidgetItem class provides methods for rendering 3D bar graphs. More...

Header: | `#include <Q3DBarsWidgetItem>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS GraphsWidgets)` `target_link_libraries(mytarget PRIVATE Qt6::GraphsWidgets)`
qmake: | `QT += graphswidgets`
Inherits: | Q3DGraphsWidgetItem

- List of all members, including inherited members
- Q3DBarsWidgetItem is part of Qt Graphs C++ Classes for Widgets.

## Properties

barSeriesMargin : QSizeF barSpacing : QSizeF barSpacingRelative : bool barThickness : float columnAxis : QCategory3DAxis* floorLevel : float | multiSeriesUniform : bool primarySeries : QBar3DSeries* rowAxis : QCategory3DAxis* selectedSeries : QBar3DSeries* const valueAxis : QValue3DAxis*

## Public Functions

| Q3DBarsWidgetItem(QObject *parent = nullptr)
virtual | ~Q3DBarsWidgetItem() override
void | addAxis(QAbstract3DAxis *axis)
void | addSeries(QBar3DSeries *series)
QList<QAbstract3DAxis *> | axes() const
QSizeF | barSeriesMargin() const
QSizeF | barSpacing() const
float | barThickness() const
QCategory3DAxis * | columnAxis() const
float | floorLevel() const
void | insertSeries(int index, QBar3DSeries *series)
bool | isBarSpacingRelative() const
bool | isMultiSeriesUniform() const
QBar3DSeries * | primarySeries() const
void | releaseAxis(QAbstract3DAxis *axis)
void | removeSeries(QBar3DSeries *series)
`(since 6.10)` void | renderSliceToImage(int requestedIndex, QtGraphs3D::SliceCaptureType sliceType)
QCategory3DAxis * | rowAxis() const
QBar3DSeries * | selectedSeries() const
QList<QBar3DSeries *> | seriesList() const
void | setBarSeriesMargin(QSizeF margin)
void | setBarSpacing(QSizeF spacing)
void | setBarSpacingRelative(bool relative)
void | setBarThickness(float thicknessRatio)
void | setColumnAxis(QCategory3DAxis *axis)
void | setFloorLevel(float level)
void | setMultiSeriesUniform(bool uniform)
void | setPrimarySeries(QBar3DSeries *series)
void | setRowAxis(QCategory3DAxis *axis)
void | setValueAxis(QValue3DAxis *axis)
QValue3DAxis * | valueAxis() const

## Signals

void | barSeriesMarginChanged(QSizeF margin)
void | barSpacingChanged(QSizeF spacing)
void | barSpacingRelativeChanged(bool relative)
void | barThicknessChanged(float thicknessRatio)
void | columnAxisChanged(QCategory3DAxis *axis)
void | floorLevelChanged(float level)
void | multiSeriesUniformChanged(bool uniform)
void | primarySeriesChanged(QBar3DSeries *series)
void | rowAxisChanged(QCategory3DAxis *axis)
void | selectedSeriesChanged(QBar3DSeries *series)
`(since 6.10)` void | sliceImageChanged(const QImage &image)
void | valueAxisChanged(QValue3DAxis *axis)

## Detailed Description

This class enables developers to render 3D bar graphs and view them by freely rotating the scene. Rotation is achieved by holding down the right mouse button and moving the mouse, while zooming is accomplished using the mouse wheel. If enabled, selection is performed with the left mouse button. The scene can be reset to the default camera view by clicking the mouse wheel. On touch devices, rotation is achieved by tap-and-move, selection by tap-and-hold, and zooming by pinch.

If no axes are set explicitly for Q3DBarsWidgetItem, temporary default axes without labels are created. These default axes can be modified via axis accessors, but as soon as any axis is set explicitly for the orientation, the default axis for that orientation is destroyed.

Q3DBarsWidgetItem supports more than one visible series at the same time. All series don't need to have the same number of rows and columns. Row and column labels are taken from the first added series unless explicitly defined for row and column axes.

Q3DBarsWidgetItem has transparency support. This feature allows you to adjust the opacity of the bars, making them partially see-through, fully transparent, or opaque.

### How to construct a minimal Q3DBarsWidgetItem graph

First, construct an instance of Q3DBarsWidgetItem:

     QQuickWidget quickWidget;
     Q3DBarsWidgetItem bars;
     bars.setWidget(&quickWidget);
     bars.widget()->setMinimumSize(QSize(256, 256));

After constructing Q3DBarsWidgetItem, you can set the data window by changing the range on the row and column axes. It is not mandatory, as the data window will default to showing all of the data in the series. If the amount of data is large, it is usually preferable to show just a portion of it. For example, let's set the data window to display the first five rows and columns:

     bars.rowAxis()->setRange(0, 4);
     bars.columnAxis()->setRange(0, 4);

Now, Q3DBarsWidgetItem is ready to receive data to be rendered. Create a series with one row of 5 values:

     QBar3DSeries series;
     QBarDataRow data;
     data << QBarDataItem(1.0f) << QBarDataItem(3.0f) << QBarDataItem(7.5f) << QBarDataItem(5.0f)
          << QBarDataItem(2.2f);
     series.dataProxy()->addRow(data);
     bars.addSeries(&series);

Note: We set the data window to 5 x 5, but we are adding only one row of data. This is okay; the rest of the rows will just be blank.

Finally you will need to set it visible:

     bars.widget()->show();

The complete code needed to create and display this graph is:

     #include <QtGraphs>
     #include <QtGraphsWidgets/q3dbarswidgetitem.h>
     #include <QtWidgets/qapplication.h>
     int main(int argc, char **argv)
     {
         QApplication app(argc, argv);

         QQuickWidget quickWidget;
         Q3DBarsWidgetItem bars;
         bars.setWidget(&quickWidget);
         bars.widget()->setMinimumSize(QSize(256, 256));
         bars.rowAxis()->setRange(0, 4);
         bars.columnAxis()->setRange(0, 4);
         QBar3DSeries series;
         QBarDataRow data;
         data << QBarDataItem(1.0f) << QBarDataItem(3.0f) << QBarDataItem(7.5f) << QBarDataItem(5.0f)
              << QBarDataItem(2.2f);
         series.dataProxy()->addRow(data);
         bars.addSeries(&series);
         bars.widget()->show();

         return app.exec();
     }

And this is what those few lines of code produce:

The scene can be rotated, zoomed into, and a bar can be selected to view its value, but no other interactions are included in this minimal code example. You can learn more by familiarizing yourself with the examples provided, like the Simple Bar Graph.

See also Q3DScatterWidgetItem, Q3DSurfaceWidgetItem, and Qt Graphs C++ Classes for 3D.

## Property Documentation

### barSeriesMargin : QSizeF

Margin between series columns in X and Z dimensions. Sensible values are on the range [0,1).

Preset to `(0.0, 0.0)` by default. This property enables showing bars from different series side by side, but with space between columns.

Access functions:

QSizeF | barSeriesMargin() const
void | setBarSeriesMargin(QSizeF margin)

Notifier signal:

void | barSeriesMarginChanged(QSizeF margin)

See also barSpacing.

### barSpacing : QSizeF

Bar spacing in the X and Z dimensions.

Preset to `(1.0, 1.0)` by default. Spacing is affected by the barSpacingRelative property.

Access functions:

QSizeF | barSpacing() const
void | setBarSpacing(QSizeF spacing)

Notifier signal:

void | barSpacingChanged(QSizeF spacing)

See also barSpacingRelative, multiSeriesUniform, and barSeriesMargin.

### barSpacingRelative : bool

This property holds whether spacing is absolute or relative to bar thickness.

If it is `true`, the value of `0.0` means that the bars are placed side-to-side, `1.0` means that a space as wide as the thickness of one bar is left between the bars, and so on. Preset to `true`.

Access functions:

bool | isBarSpacingRelative() const
void | setBarSpacingRelative(bool relative)

Notifier signal:

void | barSpacingRelativeChanged(bool relative)

### barThickness : float

This property holds the bar thickness ratio between the X and Z dimensions.

The value `1.0` means that the bars are as wide as they are deep, whereas `0.5` makes them twice as deep as they are wide. Preset to `1.0` by default.

Access functions:

float | barThickness() const
void | setBarThickness(float thicknessRatio)

Notifier signal:

void | barThicknessChanged(float thicknessRatio)

### columnAxis : QCategory3DAxis*

This property holds the axis attached to the active column.

Sets the axis of the active column to axis. Implicitly calls addAxis() to transfer the ownership of the axis to this graph.

If axis is null, a temporary default axis with no labels is created. This temporary axis is destroyed if another axis is set explicitly to the same orientation.

Access functions:

QCategory3DAxis * | columnAxis() const
void | setColumnAxis(QCategory3DAxis *axis)

Notifier signal:

void | columnAxisChanged(QCategory3DAxis *axis)

See also addAxis() and releaseAxis().

### floorLevel : float

This property holds the floor level for the bar graph in Y-axis data coordinates.

The actual floor level will be restricted by the Y-axis minimum and maximum values. Defaults to zero.

Access functions:

float | floorLevel() const
void | setFloorLevel(float level)

Notifier signal:

void | floorLevelChanged(float level)

### multiSeriesUniform : bool

This property holds whether bars are to be scaled with proportions set to a single series bar even if there are multiple series displayed.

If set to `true`, bar spacing will be correctly applied only to the X-axis. Preset to `false` by default.

Access functions:

bool | isMultiSeriesUniform() const
void | setMultiSeriesUniform(bool uniform)

Notifier signal:

void | multiSeriesUniformChanged(bool uniform)

### primarySeries : QBar3DSeries*

This property holds the primary series of the graph.

Sets series as the primary series of the graph. The primary series determines the row and column axis labels when the labels are not explicitly set to the axes.

If the specified series is not yet added to the graph, setting it as the primary series will also implicitly add it to the graph.

If the primary series itself is removed from the graph, this property resets to default.

If series is null, this property resets to default. Defaults to the first added series or zero if no series are added to the graph.

Access functions:

QBar3DSeries * | primarySeries() const
void | setPrimarySeries(QBar3DSeries *series)

Notifier signal:

void | primarySeriesChanged(QBar3DSeries *series)

### rowAxis : QCategory3DAxis*

This property holds the axis attached to the active row.

Sets the axis of the active row to axis. Implicitly calls addAxis() to transfer the ownership of the axis to this graph.

If axis is null, a temporary default axis with no labels is created. This temporary axis is destroyed if another axis is set explicitly to the same orientation.

Access functions:

QCategory3DAxis * | rowAxis() const
void | setRowAxis(QCategory3DAxis *axis)

Notifier signal:

void | rowAxisChanged(QCategory3DAxis *axis)

See also addAxis() and releaseAxis().

### `[read-only]` selectedSeries : QBar3DSeries* const

This property holds the selected series or a null value.

If selectionMode has the `SelectionMultiSeries` flag set, this property holds the series that owns the selected bar.

Access functions:

QBar3DSeries * | selectedSeries() const

Notifier signal:

void | selectedSeriesChanged(QBar3DSeries *series)

### valueAxis : QValue3DAxis*

Sets the active value axis (the Y-axis) to axis. Implicitly calls addAxis() to transfer the ownership of axis to this graph.

If axis is null, a temporary default axis with no labels and an automatically adjusting range is created. This temporary axis is destroyed if another axis is set explicitly to the same orientation.

Access functions:

QValue3DAxis * | valueAxis() const
void | setValueAxis(QValue3DAxis *axis)

Notifier signal:

void | valueAxisChanged(QValue3DAxis *axis)

See also addAxis() and releaseAxis().

## Member Function Documentation

### `[explicit]` Q3DBarsWidgetItem::Q3DBarsWidgetItem(QObject *parent = nullptr)

Constructs a new 3D bar graph with the optional parent.

### `[override virtual noexcept]` Q3DBarsWidgetItem::~Q3DBarsWidgetItem()

Destroys the 3D bar graph.

### void Q3DBarsWidgetItem::addAxis(QAbstract3DAxis *axis)

Adds axis to the graph. The axes added via addAxis are not yet taken to use, addAxis is simply used to give the ownership of the axis to the graph. The axis must not be null or added to another graph.

See also releaseAxis(), setValueAxis(), setRowAxis(), and setColumnAxis().

### void Q3DBarsWidgetItem::addSeries(QBar3DSeries *series)

Adds the series to the graph. A graph can contain multiple series, but only one set of axes, so the rows and columns of all series must match for the visualized data to be meaningful. If the graph has multiple visible series, only the primary series will generate the row or column labels on the axes in cases where the labels are not explicitly set for the axes. If the newly added series has specified a selected bar, it will be highlighted and any existing selection will be cleared. Only one added series can have an active selection.

See also seriesList(), primarySeries, and Q3DGraphsWidgetItem::hasSeries().

### QList<QAbstract3DAxis *> Q3DBarsWidgetItem::axes() const

Returns the list of all added axes.

See also addAxis().

### void Q3DBarsWidgetItem::insertSeries(int index, QBar3DSeries *series)

Inserts the series into the position index in the series list. If the series has already been added to the list, it is moved to the new index.

Note: When moving a series to a new index that is after its old index, the new position in the list is calculated as if the series was still in its old index, so the final index is actually the index decremented by one.

See also addSeries(), seriesList(), and Q3DGraphsWidgetItem::hasSeries().

### void Q3DBarsWidgetItem::releaseAxis(QAbstract3DAxis *axis)

Releases the ownership of the axis back to the caller, if it is added to this graph. If the released axis is in use, a new default axis will be created and set active.

If the default axis is released and added back later, it behaves as any other axis would.

See also addAxis(), setValueAxis(), setRowAxis(), and setColumnAxis().

### void Q3DBarsWidgetItem::removeSeries(QBar3DSeries *series)

Removes the series from the graph.

See also Q3DGraphsWidgetItem::hasSeries().

### `[since 6.10]` void Q3DBarsWidgetItem::renderSliceToImage(int requestedIndex, QtGraphs3D::SliceCaptureType sliceType)

Exports the requested slice view to an image. The exported slice is bars of row or column, which is defined by sliceType, at a given requestedIndex.

The sliceImageChanged signal is emitted when the image is ready, and can be captured as follows:

     connect(item, &Q3DBarsWidgetItem::sliceImageChanged, this, [](const QImage &image) {
         // ~~~
     });

     item->renderSliceToImage(sliceType, index);

The image is rendered with the current antialiasing settings.

This function was introduced in Qt 6.10.

See also QQuickItem::grabToImage() and sliceImageChanged().

### QList<QBar3DSeries *> Q3DBarsWidgetItem::seriesList() const

Returns the list of series added to this graph.

See also Q3DGraphsWidgetItem::hasSeries().

### `[signal, since 6.10]` void Q3DBarsWidgetItem::sliceImageChanged(const QImage &image)

Emitted when renderSliceToImage has prepared the image.

This function was introduced in Qt 6.10.