Hi!
I was wondering if it's possible to resize the QCPLegend when grabbing the side of the Legend.
I used this
this->legend->setSelectableParts(QCPLegend::spLegendBox | QCPLegend::spItems);
then I connected the signals :
connect(this, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePressSignal(QMouseEvent*))); connect(this, SIGNAL(mouseRelease(QMouseEvent*)), this, SLOT(mouseReleaseSignal(QMouseEvent*)));
so i'm keeping the position I pressed :
void Class::mousePressSignal(QMouseEvent *event) { if (this->legend->selectTest(event->pos(), false) > 0) { if(QCPLegend::SelectablePart::spLegendBox == this->legend->selectedParts()) { _resizingLegend = true; QPointF mousePoint((event->pos().x()-this->axisRect()->left())/(double)this->axisRect()->width(), (event->pos().y()-this->axisRect()->top())/(double)this->axisRect()->height()); _resizeLegendOrigin = mousePoint; } } }
and in mouseReleaseSignal:
void Class::mouseReleaseSignal(QMouseEvent *event) { if(_resizingLegend) { int xPos = event->pos().x(); int yPos = event->pos().y(); double difference = -1; QPointF mousePoint((xPos-this->axisRect()->left())/(double)this->axisRect()->width(), (yPos-this->axisRect()->top())/(double)this->axisRect()->height()); // shorten it if(xPos > _resizeLegendOrigin.x()) difference = mousePoint.x() - _resizeLegendOrigin.x(); else // make it bigger difference = _resizeLegendOrigin.x() - mousePoint.x(); QRectF rect = this->axisRect()->insetLayout()->insetRect(0); qreal left = rect.x(); rect.setLeft(left+difference); this->axisRect()->insetLayout()->setInsetRect(0, rect); _resizingLegend = false; this->replot(); } }
But the legend doesn't seem to resize for some reasons or am I missing something?
Thank you!