Qt Graphs Migration from Qt DataVisualization
The API and functionality between Qt DataVisualization and Qt Graphs have 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:
- QML import statement
- CMake module inclusion
- qmake module inclusion
- Widget application creation
- Requirement to use OpenGL backend
- Removed classes
- Removed APIs
- Changed APIs
QML Import Statement
The import statement in Qt DataVisualization:
import QtDataVisualization
has to be changed to:
import QtGraphs
for Qt Graphs.
CMake Module Inclusion
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.
Qmake Module Inclusion
The inclusion in Qt DataVisualization:
QT += datavisualization
has to be changed to:
QT += graphs
for Qt Graphs.
Widget Application Creation
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));
Requirement to Use OpenGL Backend
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.
Removed classes
- Q3DCamera
- Q3DLight
- Q3DObject
- Q3DTheme
Removed APIs
- hasContext
- shadowsSupported
- reflection
- reflectivity
Changed APIs
- optimizationHint
- renderingMode
- renderToImage
- ColorGradient and ColorGradientStop
- ThemeColor
- Data APIs
- Camera APIs
- Theme APIs
- Enums
optimizationHint
Legacy
is now the mode that was OptimizationDefault
in QtDataVisualization. Default
uses instancing, and should be used for all targets that support it.
renderingMode
RenderDirectToBackground_NoClear
has been removed, as it was already obsolete in QtDataVisualization in Qt 6.
renderToImage
renderToImage
now returns QSharedPointer<QQuickItemGrabResult>
instead of a QImage
, and does not take msaaSamples
as a parameter anymore.
ColorGradient and ColorGradientStop
ColorGradient
is now Gradient
and ColorGradientStop
GradientStop
.
ThemeColor
ThemeColor
is now Color
.
Data APIs
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);
Camera APIs
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 Abstract3DGraph.
Theme APIs
As Q3DTheme has been 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
can now be found from Abstract3DGraph.
In addition, windowColor
has been 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 controller 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).
Enums
All enums have been turned into scoped enums, for example QAbstract3DGraph::ShadowQualityLow
has been converted to QtGraphs3D::ShadowQuality::Low
.
© 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.