I have set the boundingRect()
of my QGraphicsItem
to a certain coordinate on the scene. How can I change the coordinates based on the QGraphicsItem::mouseMoveEvent
?
Below is the code I have written. But this code only sets the position of the shape I drew within the boundingRect()
to a coordinate inside the boundingRect()
. What I want to be able to do is move the entire QGraphicsItem
to a set coordinate.
void QGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mouseMoveEvent(event);
if (y()>=394 && y()<425) //if in the range between 425 and 394 I want it to move to 440.
{
setPos(440, y());
}
else if ... //Other ranges such as that in the first if statement
{
... //another y coordinate
}
else //If the item is not in any of the previous ranges it's y coordinate is set to 0
{
setPos(0,y()); //I had expected the item to go to y = 0 on the scene not the boundingRect()
}
}
The scene is 880 by 860 and the boundingRect()
is set like this:
QRectF QGraphicsItem::boundingRect() const
{
return QRectF(780,425,60,30);
}