itemChange not called
Solved
General and Desktop
-
Hi,
I have a rectangle I would like to keep inside the plot area as shown below.
To do so I have reimplemented QGraphicsRectItem as below:CallOut::CallOut(QRectF rect, QRectF plotArea) : QGraphicsRectItem(rect), m_plotArea(plotArea) { } QVariant CallOut::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) { if (change == ItemPositionChange) { // value is the new position. QPointF newPos = value.toPointF(); if (!m_plotArea.contains(newPos)) { newPos.setX(qMin(m_plotArea.right(), qMax(newPos.x(), m_plotArea.left()))); newPos.setY(qMin(m_plotArea.bottom(), qMax(newPos.y(), m_plotArea.top()))); return newPos; } qDebug() << "ItemPositionChange"; } qDebug() << "itemChange"; return QGraphicsItem::itemChange(change, value); }
Then I implement my rectangle as follows:
testRect = new CallOut(QRectF(0, 0, 100, 100), plotArea); testRect->setFlag(QGraphicsItem::ItemIsMovable); scene->addItem(testRect);
The issue is that itemChange is never called when I move the rectangle?
What did I made wrong?
-
Hi,
To avoid massive change notifications, there are not all reported as default.
So i think you need
testRect->setFlag(QGraphicsItem::ItemSendsScenePositionChanges);