The API and functionality between Qt DataVisualization and Qt Graphs was kept mostly unchanged. However, there are some differences that need to be taken into consideration when migrating your application from Qt DataVisualization to Qt Graphs:
The import statement in Qt DataVisualization:
import QtDataVisualization
is changed to:
import QtGraphs
for Qt Graphs.
The inclusion in Qt DataVisualization:
find_package(Qt6 REQUIRED COMPONENTS DataVisualization)
target_link_libraries(mytarget PRIVATE Qt6::DataVisualization)
is changed to:
find_package(Qt6 REQUIRED COMPONENTS Graphs)
target_link_libraries(mytarget PRIVATE Qt6::Graphs)
for Qt Graphs.
The inclusion in Qt DataVisualization:
QT += datavisualization
is changed to:
QT += graphs
for Qt Graphs.
To create a Graph in a widget application, change your code from:
Q3DBars *barGraph = new Q3DBars(); QWidget *barsWidget = new QWidget(); QWidget *container = QWidget::createWindowContainer(barGraph, barsWidget); auto *hLayout = new QHBoxLayout(barsWidget); hLayout->addWidget(container, 1);
to:
QQuickWidget *quickWidget = new QQuickWidget(); Q3DBarsWidgetItem *barGraph = new Q3DBarsWidgetItem(); barGraph->setWidget(quickWidget); auto *hLayout = new QHBoxLayout(quickWidget);
To use Qt Graphs 3D, you no longer need to force using the OpenGL backend:
// Remove this line qputenv("QSG_RHI_BACKEND", "opengl");
Qt Graphs uses Qt Quick 3D for rendering, and as such supports the rendering backends native to the platform it is being run on.
Legacy
is now the mode that was
OptimizationDefault
in QtDataVisualization.
Default
uses instancing, and should be used for all targets that support it.
RenderDirectToBackground_NoClear
has been removed, as it was already obsolete in QtDataVisualization in Qt 6.
renderToImage
now returns
QSharedPointer<QQuickItemGrabResult>
而不是
QImage
, and does not take
msaaSamples
as a parameter anymore.
ColorGradient
现为
Gradient
and
ColorGradientStop
GradientStop
.
ThemeColor
现为
Color
.
No need to create data arrays with
new
anymore. For example, when data was created for bar graph in Qt DataVisualization, it was done like this:
// Qt DataVisualization approach. QBarDataRow *data = new QBarDataRow; *data << 1.0f << 3.0f << 7.5f << 5.0f << 2.2f;
Now, it is done like this:
// Qt Graphs approach. QBarDataRow data; data << 1.0f << 3.0f << 7.5f << 5.0f << 2.2f; series->dataProxy()->addRow(data);
As Q3DCamera was removed, the required functions from it were moved.
cameraPreset, cameraTargetPosition, cameraXRotation, cameraYRotation, cameraZoomLevel, wrapCameraXRotation, and wrapCameraYRotation
are now the parts of
GraphsItem3D
.
As Q3DTheme was removed and the theming between 2D and 3D graphs unified, some of the required functions from it have been moved, and the rest can be found from the replacement,
GraphsTheme
.
lightColor, ambientLightStrength, lightStrength, and shadowStrength
are now implemented on
GraphsItem3D
.
windowColor
was removed.
backgroundColor
now does what
windowColor
used to do, and a new function
plotAreaBackgroundColor
replaces the functionality of what
backgroundColor
previously did.
The generic color scheme of the whole graph is now controlled by a color scheme property, and series colors by a theme property. If color scheme is not explicitly set, it will follow the desktop theming (Light/Dark).
In Qt Graphs, all the enums are implemented as scoped enums, for example, for the
QAbstract3DGraph::ShadowQualityLow
in Qt DataVisualization, the corresponding enum in Qt Graphs is
QtGraphs3D::ShadowQuality::Low
.