QCustomPlot Discussion and Comments

Issue is : QCPItemRect is not adding on QCustomPlotReturn to overview

Hello Team,

I have few questions related to QCustomPlot-

1)Can we add QGraphicsItem on QCustomPlot?

2) QCPItemRect *rect1= new QCPItemRect(ui->customPlot);

ui->customPlot->addItem(rect); //Here I am not able to find addItem to add the QCPItemRect on QCustomPlot, Compiler gives
error, Its not a member of CustomPlot. I am able to draw Rect but not able to add Rect Item on
QcustomPlot so its not movable and not selectable...Please anybody having any information about this issue how we can fixed please let me know..Thanks in advance.

rect1->setPen(QPen(QColor(50, 0, 0, 100)));
rect1->setSelectedPen(QPen(QColor(0, 255, 0, 100)));
rect1->setBrush(QBrush(QColor(50, 0, 0, 100)));
rect1->setSelectedBrush(QBrush(QColor(0, 255, 0, 100)));


according to the docs, addItem no longer exists. it looks like its functionality has been replaced by
it also says in the docs that the constructor for the item should already be calling it.

Hello Lan,

Thank You So Much for replied.

Can you please give me some example to adding the QCPRectItem on QCustomPlot.
I tried as you suggested but still not able to add the item , I am inherited from QCustomPlot class to my class still getting false value from bool value = this->registerItem(rect);

QCPItemRect *rect = new QCPItemRect(this);
bool value = this->registerItem(rect);


as i pointed out previously, according to the docs it is already called. in the source code, registerItem will return false if the item was already added to the plot (which it was)..

As a suggestion to the creator, it should probably return true in this scenario simply because the objective (the item being in the qcustomplot) was achieved.

Hello Lan,

Thanks for valuable input, Its working fine.

One more question I have, Can we use QGraphicsItem on QcustomPlot?
I tried to merged QGraphicsView on QCustomPlot, But It does not work, gets disappear my QCustomPlot, Only QGraphicsView visible.

So is there any way to get QGraphicsItem on QCustomPlot, Please let me know.

Thanks and Regards,

I dont know if you are able to draw over the qcustomplot using qt drawing stuff, but i do know that the qcustomplot code doesnt support QGraphicsItems. it only uses its own custom items.

Hello Lan,

Do you have idea about rotate the QCPItemRect with an angle?
Please let me know if you know.


i dont know how to do it other than reimplementing the draw function and using the painter rotate function. Doesn't mean it can't be done. I just dont know how.

Hello Lan,

I am using 2.0 version, I want to get the position on corner of QCPItemRect which i have created to change the cursor for resize the rectangle, I am searching mouse hover and contain API in QCustomPlot.cpp but unable to find this.

Do you have any other alternative approach to change the cursor on four corner for resizing the Item?

Thanks & Regards,