- Qt 6.8
- Qt Graphs
- C++ Classes
- QtGraphs
- Q3DSurfaceWidgetItem
- Qt Graphs | Commercial or GPLv3

# Q3DSurfaceWidgetItem Class

The Q3DSurfaceWidgetItem class provides methods for rendering 3D surface plots. More...

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

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

## Properties

axisX : QValue3DAxis* axisY : QValue3DAxis* axisZ : QValue3DAxis* | flipHorizontalGrid : bool selectedSeries : QSurface3DSeries* const

## Public Functions

| Q3DSurfaceWidgetItem(QObject *parent = nullptr)
virtual | ~Q3DSurfaceWidgetItem() override
void | addAxis(QValue3DAxis *axis)
void | addSeries(QSurface3DSeries *series)
QList<QValue3DAxis *> | axes() const
QValue3DAxis * | axisX() const
QValue3DAxis * | axisY() const
QValue3DAxis * | axisZ() const
bool | flipHorizontalGrid() const
void | releaseAxis(QValue3DAxis *axis)
void | removeSeries(QSurface3DSeries *series)
QSurface3DSeries * | selectedSeries() const
QList<QSurface3DSeries *> | seriesList() const
void | setAxisX(QValue3DAxis *axis)
void | setAxisY(QValue3DAxis *axis)
void | setAxisZ(QValue3DAxis *axis)
void | setFlipHorizontalGrid(bool flip)

## Signals

void | axisXChanged(QValue3DAxis *axis)
void | axisYChanged(QValue3DAxis *axis)
void | axisZChanged(QValue3DAxis *axis)
void | flipHorizontalGridChanged(bool flip)
void | selectedSeriesChanged(QSurface3DSeries *series)

## Detailed Description

This class enables developers to render 3D surface plots and to view them by rotating the scene freely. The visual properties of the surface such as draw mode and shading can be controlled via QSurface3DSeries.

The Q3DSurfaceWidgetItem supports selection by showing a highlighted ball on the data point where the user has clicked with the left mouse button (when the default input handler is in use) or selected via QSurface3DSeries. The selection pointer is accompanied by a label, which in the default case shows the value of the data point and the coordinates of the point.

The value range and the label format shown on the axis can be controlled through QValue3DAxis.

To rotate the graph, hold down the right mouse button and move the mouse. Zooming is done using the mouse wheel. Both actions assume the default input handler is in use.

If no axes are set explicitly for Q3DSurfaceWidgetItem, temporary default axes with no 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.

### How to construct a minimal Q3DSurfaceWidgetItem graph

First, construct Q3DSurfaceWidgetItem. Since we are running the graph as a top-level window in this example, we need to clear the `Qt::FramelessWindowHint` flag, which is set by default:

     QQuickWidget quickWidget;
     Q3DSurfaceWidgetItem surface;
     surface.setWidget(&quickWidget);
     surface.widget()->setMinimumSize(QSize(256, 256));

Now Q3DSurfaceWidgetItem is ready to receive data to be rendered. Create data elements to receive values:

Note: In the new proxy-series relationship, data is held in series. Therefore, for the proxy to be able to add, delete, or edit the data, it is a prerequisite to create a series first.

     QSurfaceDataArray data;
     QSurfaceDataRow dataRow1;
     QSurfaceDataRow dataRow2;

First feed the data to the row elements and then add their pointers to the data element:

     dataRow1 << QSurfaceDataItem(0.0f, 0.1f, 0.5f) << QSurfaceDataItem(1.0f, 0.5f, 0.5f);
     dataRow2 << QSurfaceDataItem(0.0f, 1.8f, 1.0f) << QSurfaceDataItem(1.0f, 1.2f, 1.0f);
     data << dataRow1 << dataRow2;

Create a new series and set data to it:

     QSurface3DSeries series;
     series.dataProxy()->resetArray(data);
     surface.addSeries(&series);

Finally you will need to set it visible:

     surface.widget()->show();

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

     #include <QtGraphs>
     #include <QtGraphsWidgets/q3dsurfacewidgetitem.h>
     #include <QtWidgets/qapplication.h>

     int main(int argc, char **argv)
     {
         QApplication app(argc, argv);

         QQuickWidget quickWidget;
         Q3DSurfaceWidgetItem surface;
         surface.setWidget(&quickWidget);
         surface.widget()->setMinimumSize(QSize(256, 256));
         QSurfaceDataArray data;
         QSurfaceDataRow dataRow1;
         QSurfaceDataRow dataRow2;

         dataRow1 << QSurfaceDataItem(0.0f, 0.1f, 0.5f) << QSurfaceDataItem(1.0f, 0.5f, 0.5f);
         dataRow2 << QSurfaceDataItem(0.0f, 1.8f, 1.0f) << QSurfaceDataItem(1.0f, 1.2f, 1.0f);
         data << dataRow1 << dataRow2;

         QSurface3DSeries series;
         series.dataProxy()->resetArray(data);
         surface.addSeries(&series);
         surface.widget()->show();

         return app.exec();
     }

And this is what those few lines of code produce:

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

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

## Property Documentation

### axisX : QValue3DAxis*

This property holds the active x-axis.

Sets axis as the active x-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 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 * | axisX() const
void | setAxisX(QValue3DAxis *axis)

Notifier signal:

void | axisXChanged(QValue3DAxis *axis)

See also addAxis() and releaseAxis().

### axisY : QValue3DAxis*

This property holds the active y-axis.

Sets axis as the active y-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 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 * | axisY() const
void | setAxisY(QValue3DAxis *axis)

Notifier signal:

void | axisYChanged(QValue3DAxis *axis)

See also addAxis() and releaseAxis().

### axisZ : QValue3DAxis*

This property holds the active z-axis.

Sets axis as the active z-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 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 * | axisZ() const
void | setAxisZ(QValue3DAxis *axis)

Notifier signal:

void | axisZChanged(QValue3DAxis *axis)

See also addAxis() and releaseAxis().

### flipHorizontalGrid : bool

This property holds whether the horizontal axis grid is displayed on top of the graph rather than on the bottom.

In some use cases, the horizontal axis grid is mostly covered by the surface, so it can be more useful to display the horizontal axis grid on top of the graph rather than on the bottom. A typical use case for this is showing 2D spectrograms using orthographic projection with a top-down viewpoint.

If `false`, the horizontal axis grid and labels are drawn on the horizontal background of the graph. If `true`, the horizontal axis grid and labels are drawn on the opposite side of the graph from the horizontal background. Defaults to `false`.

Access functions:

bool | flipHorizontalGrid() const
void | setFlipHorizontalGrid(bool flip)

Notifier signal:

void | flipHorizontalGridChanged(bool flip)

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

This property holds the selected series or null.

If selectionMode has `MultiSeries` set, this property holds the series which owns the selected point.

Access functions:

QSurface3DSeries * | selectedSeries() const

Notifier signal:

void | selectedSeriesChanged(QSurface3DSeries *series)

## Member Function Documentation

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

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

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

Destroys the 3D surface graph.

### void Q3DSurfaceWidgetItem::addAxis(QValue3DAxis *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(), setAxisX(), setAxisY(), and setAxisZ().

### void Q3DSurfaceWidgetItem::addSeries(QSurface3DSeries *series)

Adds the series to the graph. A graph can contain multiple series, but has only one set of axes. If the newly added series has specified a selected item, it will be highlighted and any existing selection will be cleared. Only one added series can have an active selection.

See also Q3DGraphsWidgetItem::hasSeries().

### QList<QValue3DAxis *> Q3DSurfaceWidgetItem::axes() const

Returns the list of all added axes.

See also addAxis().

### void Q3DSurfaceWidgetItem::releaseAxis(QValue3DAxis *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(), setAxisX(), setAxisY(), and setAxisZ().

### void Q3DSurfaceWidgetItem::removeSeries(QSurface3DSeries *series)

Removes the series from the graph.

See also Q3DGraphsWidgetItem::hasSeries().

### QList<QSurface3DSeries *> Q3DSurfaceWidgetItem::seriesList() const

Returns the list of series added to this graph.

See also Q3DGraphsWidgetItem::hasSeries().