After getting my PythonQt to work ,thanks to Sergey, I am having troubles adding QCustomPlot to pythonQt.
I would like to use the QCustomPlot functions inside my script.
Currently I use:
QCustomPlot *graph = new QCustomPlot;
mainContext.addObject("graph",graph);
Which works a bit, I can use functions like graph.newgraph();. However, functions like graph.xAxis.setLabel("test"); don't exist, 'xAxis' is unknown. I tried to do it like the example 'PyCPPWrapperExample' but I am unable of creating a wrapper for QCustomPlot.
Help is much appreciated :)
Thanks!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
classCustomObjectWrapper : publicQObject{Q_OBJECTpublicQ_SLOTS:// add a constructorQCustomPlot*new_QCustomPlot(){returnnewQCustomPlot();}//wrapper functionsvoiddelete_QCustomPlot(QCustomPlot*o)//delete QCustomPlot object{deleteo;}voidaddGraph(QCustomPlot*o)//add a graph inside the QCustomPlot object{o->addGraph();}voidsetData(QCustomPlot*o,intgraphnum,constQVector<double>&keys,constQVector<double>&values)//set data to a certain graph. Deletes existing data inside the graph{o->graph(graphnum)->setData(keys,values);}voidreplot(QCustomPlot*o)//replot object to visualise new data{o->replot();}voidshow(QCustomPlot*o)//open new window with graph{o->show();}voidsetWindowTitle(QCustomPlot*o,QStringtitle)//set title of window of graph{o->setWindowTitle(title);}voidrescaleAxes(QCustomPlot*o,intgraphnum)//rescale axis automatically if data does not fit{o->graph(graphnum)->rescaleAxes();}voidplotLayout_insertRow(QCustomPlot*o,introw)//insert row above graph{o->plotLayout()->insertRow(row);}voidplotLayout_insertColumn(QCustomPlot*o,intcolumn)//insert column above graph{o->plotLayout()->insertColumn(column);}voidplotLayout_addElement(QCustomPlot*o,introw,intcolumn,QCPLayoutElement*element)//add text to graph at row,column{o->plotLayout()->addElement(row,column,element);}//------------------------------------------------------- Axis adjustment stuff------------------------------------------------//xAxis stuffvoidxAxis_setLabel(QCustomPlot*o,constQStringtext){o->xAxis->setLabel(text);}voidxAxis_setVisible(QCustomPlot*o,boolvisible){o->setVisible(visible);}voidxAxis_setRange(QCustomPlot*o,doubleposition,doublesize){o->xAxis->setRange(position,size);}voidxAxis_setAutoTicks(QCustomPlot*o,boolon){o->xAxis->setAutoSubTicks(on);}voidxAxis_setAutoTickLabels(QCustomPlot*o,boolon){o->xAxis->setAutoTickLabels(on);}voidxAxis_setTickVector(QCustomPlot*o,constQVector<double>&ticks){o->xAxis->setTickVector(ticks);}voidxAxis_setTickVectorLabels(QCustomPlot*o,constQVector<QString>&labels){o->xAxis->setTickVectorLabels(labels);}voidxAxis_setTickLength(QCustomPlot*o,intinside,intoutside){o->xAxis->setTickLength(inside,outside);}voidxAxis_setSubTickLength(QCustomPlot*o,intinside,intoutside){o->xAxis->setSubTickLength(inside,outside);}//xAxis2 stuffvoidxAxis2_setLabel(QCustomPlot*o,constQStringtext){o->xAxis2->setLabel(text);}voidxAxis2_setVisible(QCustomPlot*o,boolvisible){o->setVisible(visible);}voidxAxis2_setRange(QCustomPlot*o,doubleposition,doublesize){o->xAxis2->setRange(position,size);}voidxAxis2_setAutoTicks(QCustomPlot*o,boolon){o->xAxis2->setAutoSubTicks(on);}voidxAxis2_setAutoTickLabels(QCustomPlot*o,boolon){o->xAxis2->setAutoTickLabels(on);}voidxAxis2_setTickVector(QCustomPlot*o,constQVector<double>&ticks){o->xAxis2->setTickVector(ticks);}voidxAxis2_setTickVectorLabels(QCustomPlot*o,constQVector<QString>&labels){o->xAxis2->setTickVectorLabels(labels);}voidxAxis2_setTickLength(QCustomPlot*o,intinside,intoutside){o->xAxis2->setTickLength(inside,outside);}voidxAxis2_setSubTickLength(QCustomPlot*o,intinside,intoutside){o->xAxis2->setSubTickLength(inside,outside);}//yAxis stuffvoidyAxis_setLabel(QCustomPlot*o,constQStringtext){o->yAxis->setLabel(text);}voidyAxis_setVisible(QCustomPlot*o,boolvisible){o->setVisible(visible);}voidyAxis_setRange(QCustomPlot*o,doubleposition,doublesize){o->yAxis->setRange(position,size);}voidyAxis_setAutoTicks(QCustomPlot*o,boolon){o->yAxis->setAutoSubTicks(on);}voidyAxis_setAutoTickLabels(QCustomPlot*o,boolon){o->yAxis->setAutoTickLabels(on);}voidyAxis_setTickVector(QCustomPlot*o,constQVector<double>&ticks){o->yAxis->setTickVector(ticks);}voidyAxis_setTickVectorLabels(QCustomPlot*o,constQVector<QString>&labels){o->yAxis->setTickVectorLabels(labels);}voidyAxis_setTickLength(QCustomPlot*o,intinside,intoutside){o->yAxis->setTickLength(inside,outside);}voidyAxis_setSubTickLength(QCustomPlot*o,intinside,intoutside){o->yAxis->setSubTickLength(inside,outside);}//yAxis2 stuffvoidyAxis2_setLabel(QCustomPlot*o,constQStringtext){o->yAxis2->setLabel(text);}voidyAxis2_setVisible(QCustomPlot*o,boolvisible){o->setVisible(visible);}voidyAxis2_setRange(QCustomPlot*o,doubleposition,doublesize){o->yAxis2->setRange(position,size);}voidyAxis2_setAutoTicks(QCustomPlot*o,boolon){o->yAxis2->setAutoSubTicks(on);}voidyAxis2_setAutoTickLabels(QCustomPlot*o,boolon){o->yAxis2->setAutoTickLabels(on);}voidyAxis2_setTickVector(QCustomPlot*o,constQVector<double>&ticks){o->yAxis2->setTickVector(ticks);}voidyAxis2_setTickVectorLabels(QCustomPlot*o,constQVector<QString>&labels){o->yAxis2->setTickVectorLabels(labels);}voidyAxis2_setTickLength(QCustomPlot*o,intinside,intoutside){o->yAxis2->setTickLength(inside,outside);}voidyAxis2_setSubTickLength(QCustomPlot*o,intinside,intoutside){o->yAxis2->setSubTickLength(inside,outside);}};
Please not that I did NOT wrap all of the functions of QCustomPlot. I think you can easily add them yourself if you need some other function I did not wrap.
Also, I'm pretty sure that here are other, better ways to do the above but this was the only thing I could manage.The thing that I am primarily missing is the capability to do things like this:
graph.level1.level2 I can't get past level1 so all my wrapped functions that are deeper than level1 have a different but similar name with underscores.
Last edit: Poep Hoofd 2015-10-16
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
After getting my PythonQt to work ,thanks to Sergey, I am having troubles adding QCustomPlot to pythonQt.
I would like to use the QCustomPlot functions inside my script.
Currently I use:
Which works a bit, I can use functions like
graph.newgraph();
. However, functions likegraph.xAxis.setLabel("test");
don't exist, 'xAxis' is unknown. I tried to do it like the example 'PyCPPWrapperExample' but I am unable of creating a wrapper for QCustomPlot.Help is much appreciated :)
Thanks!
To answer my own question:
Add this to QCustomPlot.h:
and use this in your main:
Then, in your script/console :
Please not that I did NOT wrap all of the functions of QCustomPlot. I think you can easily add them yourself if you need some other function I did not wrap.
Also, I'm pretty sure that here are other, better ways to do the above but this was the only thing I could manage.The thing that I am primarily missing is the capability to do things like this:
graph.level1.level2
I can't get past level1 so all my wrapped functions that are deeper than level1 have a different but similar name with underscores.Last edit: Poep Hoofd 2015-10-16