Q3DScatterWidgetItem Class

The Q3DScatterWidgetItem class provides methods for rendering 3D scatter graphs. More...

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

Properties

Public Functions

Q3DScatterWidgetItem(QObject *parent = nullptr)
virtual ~Q3DScatterWidgetItem() override
void addAxis(QValue3DAxis *axis)
void addSeries(QScatter3DSeries *series)
QList<QValue3DAxis *> axes() const
QValue3DAxis *axisX() const
QValue3DAxis *axisY() const
QValue3DAxis *axisZ() const
void releaseAxis(QValue3DAxis *axis)
void removeSeries(QScatter3DSeries *series)
QScatter3DSeries *selectedSeries() const
QList<QScatter3DSeries *> seriesList() const
void setAxisX(QValue3DAxis *axis)
void setAxisY(QValue3DAxis *axis)
void setAxisZ(QValue3DAxis *axis)

Signals

void axisXChanged(QValue3DAxis *axis)
void axisYChanged(QValue3DAxis *axis)
void axisZChanged(QValue3DAxis *axis)
void selectedSeriesChanged(QScatter3DSeries *series)

Detailed Description

This class enables developers to render 3D scatter 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 to Q3DScatterWidgetItem, temporary default axes with no labels are created. These default axes can be modified via axis accessors, but as soon any axis is set explicitly for the orientation, the default axis for that orientation is destroyed.

Q3DScatterWidgetItem supports more than one series visible at the same time.

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

How to construct a minimal Q3DScatterWidgetItem graph

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

QQuickWidget quickWidget;
Q3DScatterWidgetItem scatter;
scatter.setWidget(&quickWidget);
scatter.widget()->setMinimumSize(QSize(256, 256));

Now Q3DScatterWidgetItem is ready to receive data to be rendered. Add one series of 3 QVector3D items:

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.

QScatter3DSeries series;
QScatterDataArray data;
data << QScatterDataItem(0.5f, 0.5f, 0.5f) << QScatterDataItem(-0.3f, -0.5f, -0.4f)
     << QScatterDataItem(0.0f, -0.3f, 0.2f);
series.dataProxy()->addItems(data);
scatter.addSeries(&series);

Finally you will need to set it visible:

scatter.widget()->show();

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

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

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

    QQuickWidget quickWidget;
    Q3DScatterWidgetItem scatter;
    scatter.setWidget(&quickWidget);
    scatter.widget()->setMinimumSize(QSize(256, 256));
    QScatter3DSeries series;
    QScatterDataArray data;
    data << QScatterDataItem(0.5f, 0.5f, 0.5f) << QScatterDataItem(-0.3f, -0.5f, -0.4f)
         << QScatterDataItem(0.0f, -0.3f, 0.2f);
    series.dataProxy()->addItems(data);
    scatter.addSeries(&series);
    scatter.widget()->show();

    return app.exec();
}

And this is what those few lines of code produce:

The scene can be rotated, zoomed into, and an item 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 Simple Scatter Graph.

See also Q3DBarsWidgetItem, Q3DSurfaceWidgetItem, 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().

[read-only] selectedSeries : QScatter3DSeries* const

This property holds the selected series or null.

Access functions:

QScatter3DSeries *selectedSeries() const

Notifier signal:

void selectedSeriesChanged(QScatter3DSeries *series)

Member Function Documentation

[explicit] Q3DScatterWidgetItem::Q3DScatterWidgetItem(QObject *parent = nullptr)

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

[override virtual noexcept] Q3DScatterWidgetItem::~Q3DScatterWidgetItem()

Destroys the 3D scatter graph.

void Q3DScatterWidgetItem::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 Q3DScatterWidgetItem::addSeries(QScatter3DSeries *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 *> Q3DScatterWidgetItem::axes() const

Returns the list of all added axes.

See also addAxis().

void Q3DScatterWidgetItem::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 Q3DScatterWidgetItem::removeSeries(QScatter3DSeries *series)

Removes the series from the graph.

See also Q3DGraphsWidgetItem::hasSeries().

QList<QScatter3DSeries *> Q3DScatterWidgetItem::seriesList() const

Returns the list of series added to this graph.

See also Q3DGraphsWidgetItem::hasSeries().

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.