Я установил boundingRect()
моего QGraphicsItem
на определенную координату на сцене. Как я могу изменить координаты на основе QGraphicsItem::mouseMoveEvent
?
Ниже приведен код, который я написал. Но этот код только устанавливает положение фигуры, которую я нарисовал в пределах boundingRect()
, в координату внутри boundingRect()
. Что я хочу сделать, так это переместить весь QGraphicsItem
в заданную координату.
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()
}
}
Сцена имеет разрешение 880 на 860, а boundingRect()
устанавливается следующим образом:
QRectF QGraphicsItem::boundingRect() const
{
return QRectF(780,425,60,30);
}