4

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

QCustomPlot certainly could support table models. That it doesn't is not out of necessity, but out of lack of time/willpower/manpower. It'd be an easy thing to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.