The API and functionality between Qt DataVisualization and Qt Graphs has been 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
has to be 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)
has to be 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
has to be changed to:
QT += graphs
for Qt Graphs.
Instead of creating your widget application like this:
QGuiApplication app(argc, argv); Q3DScatter scatter; scatter.setFlags(scatter.flags() ^ Qt::FramelessWindowHint);
you should create it like this:
QApplication app(argc, argv); Q3DScatter scatter; scatter.setMinimumSize(QSize(256, 256));
Adding the forced OpenGL backend usage:
qputenv("QSG_RHI_BACKEND", "opengl");
is no longer required. 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.
默认
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 QtDataVisualization, it was done like this:
QBarDataRow *data = new QBarDataRow; *data << 1.0f << 3.0f << 7.5f << 5.0f << 2.2f;
Now, it is done like this:
QBarDataRow data; data << 1.0f << 3.0f << 7.5f << 5.0f << 2.2f; series->dataProxy()->addRow(data);
As Q3DCamera has been removed, the required functions from it have been moved.
cameraPreset, cameraTargetPosition, cameraXRotation, cameraYRotation, cameraZoomLevel, wrapCameraXRotation, and wrapCameraYRotation
can now be found from
AbstractGraph3D
.
All enums have been turned into scoped enums, for example
QAbstract3DGraph::ShadowQualityLow
has been converted to
QAbstract3DGraph::ShadowQuality::Low
.