Qt Graphs. Building 2d plot using c++ only.
-
Maybe I misunderstood.
Sorry, I'm still having trouble understanding how to use a 2d "QtGraph" from C++. You said "the new QtGraphs module uses a QML backend for rendering, even when you use its C++ / QtWidget API." That's fine, but how do you construct & interact with a 2d "Qt Graph" (which uses a "QML backend")?
I see that there are C++ classes for Qt Graphs, like https://doc.qt.io/qt-6/qlineseries.html, but this seems to just be a class which represents data? What's the C++ class which I use as the view? Is there some QWidget-based class which I'd then add the series to?
-
Maybe I misunderstood.
Sorry, I'm still having trouble understanding how to use a 2d "QtGraph" from C++. You said "the new QtGraphs module uses a QML backend for rendering, even when you use its C++ / QtWidget API." That's fine, but how do you construct & interact with a 2d "Qt Graph" (which uses a "QML backend")?
I see that there are C++ classes for Qt Graphs, like https://doc.qt.io/qt-6/qlineseries.html, but this seems to just be a class which represents data? What's the C++ class which I use as the view? Is there some QWidget-based class which I'd then add the series to?
@SandSnip3r said in Qt Graphs. Building 2d plot using c++ only.:
What's the C++ class which I use as the view? Is there some QWidget-based class which I'd then add the series to?
The QtGraphs Module is still under development.
I think the correct class isQGraphsView
, but it doesn't seem to exist yet.It's mentioned here as this function returns this type.
-
Isn't the Graphs moved out of technical preview as of 6.8? I thought I saw something, but cant find it again, about the qt widgets support for 2d graphs being lagging. Do you know if Qt communicates this roadmap externally? I don't see anything about it the Jira board of known issues.
-
Does Graphs even aim to replace the current 2d qt charts? Or is Graphs just meant to be a 3d thing?
If it does, is there a way to use the qml-based Qt Graphs from C++?
-
Isn't the Graphs moved out of technical preview as of 6.8? I thought I saw something, but cant find it again, about the qt widgets support for 2d graphs being lagging. Do you know if Qt communicates this roadmap externally? I don't see anything about it the Jira board of known issues.
@SandSnip3r said in Qt Graphs. Building 2d plot using c++ only.:
Isn't the Graphs moved out of technical preview as of 6.8?
Should be but as you can see from OPs question
QGraphsView
, the C++ API to access the QML backend is mentioned in the documentation but not implemented nor it has it's own documentation page... the links lead to nowhere... :(Maybe use the QML interface for now and handle it like any other hybrid QML/C++ app
QGraphs
should be 2D and 3D + C++ and QML... but not everything seem to work right now. -
QML uses the local 3D engine of the operating system to render the Plot, rather than the traditional GraphicsView technology used under QtWidgets. This change may be more modern and beneficial for the Qt team to focus on optimizing one framework and reducing costs. The main.qml in the new example is also easy to understand.
The first problem is that the frame rate of QML is low for cheap laptops without independent graphics cards. One important reason for using Qt in the beginning was an example called "10000 chips" (I'm not sure if the number of zeros is correct) , which surprisingly runs very smoothly on old Ubuntu netbooks , with basic Intel core graphics . The rendering effect of QtWidgets achieves the best balance between platform universality, usability, and aesthetics. The new QML is clearly more suitable for mobile devices and morden PCs.
In addition, it is also a common function to directly obtain mouse click messages from internal Chart objects to the outside C++ application , such as calculating new interpolation parameters based on user clicks. Before QtCharts, these were generally implemented using classical Qwt. I think the dense signal slot interaction between QML and C++is another big challenge.
-
Hello!! I found GraphsView QML Type, but I did not find it c++ class. I found it in the closed part of the library - qgraphsview_p.h
Why? How to build a 2d plot using C++ classes? QValueAxis and other classes are presented in C++, but not QGraphsView@Vernat said in Qt Graphs. Building 2d plot using c++ only.:
QValueAxis and other classes are presented in C++, but not QGraphsView
Currently, we can subclass QValueAxis in C++ to add our own functionality, and expose our custom subclass to QML (via
QML_ELEMENT
).From what I can see, QGraphsView inherits QQuickItem, so I doubt it's intended to be used in pure C++ (at least not until we have a full-fledged C++ API for Qt Quick). But I've asked Qt R&D for official clarification on QGraphsView: https://bugreports.qt.io/browse/QTBUG-138456
How to build a 2d plot using C++ classes?
From what I can see, there is no public C++ API for 2D graphs at this time. I don't know if it's on the roadmap or not, but there is a C++ API for 3D graphs: https://doc.qt.io/qt-6/graphs-3d-widgets.html
-
It looks like the GraphsView API will be QML-only. Integration with C++ is done via QQuickWidget: https://doc.qt.io/qt-6/qtgraphs-2d-quickwidgetgraphs-example.html
-
You can even do it without a .qml file in 6.9 by using the
QQuickWidget::setInitialProperties
andQQuickWidget::loadFromModule
:QPieSeries* pieSeries = new QPieSeries(&app); // populate it QQuickWidget* graphsView = new QQuickWidget(); graphsView->setResizeMode(QQuickWidget::SizeRootObjectToView); graphsView->setInitialProperties({{"seriesList", QVariant::fromValue(pieSeries)}}); graphsView->loadFromModule("QtGraphs", "GraphsView");
-
You can even do it without a .qml file in 6.9 by using the
QQuickWidget::setInitialProperties
andQQuickWidget::loadFromModule
:QPieSeries* pieSeries = new QPieSeries(&app); // populate it QQuickWidget* graphsView = new QQuickWidget(); graphsView->setResizeMode(QQuickWidget::SizeRootObjectToView); graphsView->setInitialProperties({{"seriesList", QVariant::fromValue(pieSeries)}}); graphsView->loadFromModule("QtGraphs", "GraphsView");
@GrecKo said in Qt Graphs. Building 2d plot using c++ only.:
You can even do it without a .qml file in 6.9 by using the
QQuickWidget::setInitialProperties
andQQuickWidget::loadFromModule
:QPieSeries* pieSeries = new QPieSeries(&app); // populate it QQuickWidget* graphsView = new QQuickWidget(); graphsView->setResizeMode(QQuickWidget::SizeRootObjectToView); graphsView->setInitialProperties({{"seriesList", QVariant::fromValue(pieSeries)}}); graphsView->loadFromModule("QtGraphs", "GraphsView");
Amazing! How to create a line serial that using DATETIME as X and double as Y in C++ follow this example ?
For example, a 3-days weather forcast line graph , 2 hours / point ?
Thank you!
-
J JonB referenced this topic