QAbstractListModel and QCustomPlot
-
Hello Everybody,
is it possible to create a QML Window plus QCustomPlot Window within a QAbstractListModel in Qt6? I write a particle simulation and I want to draw the particles in QML and draw some physical quantities in separate plots.
Kind regards,
Tobias -
Hi,
A model does not have any visual presence. There might be views on top of it though.
What exactly is your architecture ?
-
@SGaist Hello SGaist,
I load the QAbstractlismodel Hardcoreentrymodel with
qmlRegisterSingletonInstance("hardcoresystem", 1, 0, "Hardcoreentrymodel", &entryModel);
and then
QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/qt_qml/Main.qml"))); return app.exec();
in the main function. In Main.qml I import hardcoresystem 1.0
Or, what do you mean with architecture?
Tobias
-
@SGaist said in QAbstractListModel and QCustomPlot:
A model does not have any visual presence.
I think that's where
QCustomPlot
comes in. From what I can gather this is an open source add on provided externally to Qt. It seems to be oriented towards QWidgets. There are various discussions in their forum about making it work with QML but QML doesn't appear to be officially supported. -
@Tobias83 More or less that.
I wanted to known how you are planning to use that model (or already using) and associate it with widgets or QML components.
-
@Bob64 said in QAbstractListModel and QCustomPlot:
@SGaist said in QAbstractListModel and QCustomPlot:
A model does not have any visual presence.
I think that's where
QCustomPlot
comes in. From what I can gather this is an open source add on provided externally to Qt. It seems to be oriented towards QWidgets. There are various discussions in their forum about making it work with QML but QML doesn't appear to be officially supported.Not really no but there might be a misunderstanding somewhere.
So I'll try to clarify:
- Models only provide data and hints. No widgets (or qml visual components for that matter)
- You can have widgets handling models such as QListView and friends but they are not part of the model.
-
@SGaist Yes, sorry - you are correct of course. I must admit that I had got more interested in the question about how well QCustomPlot works with QML in the first place. I guess I had assumed that there would be some way to define the plot from a model but you are correct that it is not obvious.
-
@Bob64 I am doing same work, but I think it is impossible. Because QcustomPlot depends on QWidgets and event loop, but the QML is other thing. In an app, they , event loop and QML, cann't run at same time. It is pity, but you can find other lib to achieve this function or you can try to recode QCustomPlot by QML which is meanful I think.
-
OK, I gave up QCustumPlot und found out that there is QtCharts. I wil try with QtCharts and QML.
Tobias
-
You should rather go with Qt Graphs. Qt Charts is also graphics view based although QML is also supported and is being deprecated.
-
@SGaist Hello SGaist,
in QtCharts I can use a model like this
ChartView { antialiasing: true anchors.fill: parent legend.visible: false LineSeries { VXYModelMapper { model: Hardcorechartmodelseries xColumn: 0 yColumn: 1 } } }
Is there also this opportunity in QtGraphs?
Tobias
-
The XYModelMapper is also there.
2/12