Use QCustomPlot
-
Hello,
I am in Qt 5.6.4 version to be able to program in 32bit. I need help to use the QCustomPlot library. I have already done the necessary installations by adding it in my project folder. To use this library, I need a QCustomPlot widget in my .ui. Except that such a widget with QCustomPlot is not in my list.
My question is: How to create a QCustomPlot widget to integrate it in the object list?Thanks for your help
-
@Raphawel said in Use QCustomPlot:
Except that such a widget with QCustomPlot is not in my list
Simply add QCustomPlot to your UI in code
-
You have to promote a QWidget (assuming QWidget is the Qt base class of QCustomPlot): https://doc.qt.io/qt-6/designer-using-custom-widgets.html
-
@Raphawel Do what @Christian-Ehrlicher suggested.
Another way is: add a QWidget in designer where you want to have your QCustomPlot. Then in code create QCustomPlot instance and use the QWidget added in designer as its parent. -
@jsulm Thanks for your help, I don't know if I followed your advice but I created a widget on my ui and promoted it to QCustomPlot, like on the picture :
(The created widget is the one selected in blue)
(Just to clarify, I wanted to create a widget to use QCustomPlot to be able to create a graph)
And now, I have to connect the function on which I will write the program to create the graph, on the created widget ? To be able to use QCustomPlot.
-
@Raphawel
Hi
Using promotion is a nice way to be able to design with a custom widget.The type in ui->XXXX will be the right one ( QCustomPlot ) and the remaining of the task is
to add data to it.Do understand you have now access to the QCustomPlot via the UI->Nameofpromotedwidget so
have this in mind if you reuse code from the examples as they often NEW another instance of QCustomPlot and you want to use the one you have promoted.Lets say you use
https://www.qcustomplot.com/index.php/tutorials/basicplottingthen all
customPlot->xxxxxshould be changed to
ui->widget->xxxxxxxto use the promoted one.
Hope this helps.
-
@mrjj Hi
Hello, I apologize for the late reply, and thank you for your help it helped me.
I managed to display a graph. So I'll post the steps to follow to use QCustomPlot (send me a message if it's not good):
1° Install QCustomPlot via this link: https://www.qcustomplot.com/index.php/download
2° Unzip the file then put these two files in your project folder.
3° Add existing files of both files, then they should appear in your tree.
4° Add printsupport in your .pro :
5° Create a widget and place it in your interface
6° Right click on the widget /Promote widget/
Normally in the interface tree, the widget should be in QCustomPlot.
7° Create a function (here makePlot() ) in which you will create your graphic (don't forget to put the function in the private slot)
8° Be careful when you call your widget : ui->name_widget->command . For example, my widget is called customplot :