简体   繁体   中英

How to plot QAbstractItemModel using QCustomPlot

Is there a direct way to pass QAbstractItemModel to QCustomPlot ? Currently I am defining two QVector<double> for Xval and yVal . When I have to plot, I update these two vectors from QAbstractItemModel to launch the plot function.

Is there any way that QCustomPlot can accept QAbstractItemModel ?

AFAIK there is not a direct support for QAbstractItemModel in QCustomPlot . I am not sure how you expect QCustomPlot to draw contents of a QAbstractItemModel . As you know the model could be a simple model or a complex one or even hierarchical. That's two much for a simple 2D plot like QCustomPlot . But there seems to be a way to assign data of a subclass of QAbstractItemModel to QCustomPlot and that's using QCPDataMap .

You should populate the data of your model in QCPDataMap and assign it to plot. That's something like :

QCPDataMap *data = new QCPDataMap();

for(int i=0; i<count; i++)
    data->insertMulti(data->constEnd(), x[i], QCPData(x[i], y[i]));

plot->graph()->setData(data);

You can generate QCPDataMap in your model using x and y values and assign it's pointer to plot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM