有没有QGraphicsItem坐标改变就相应的函数,求解答!

有没有QGraphicsItem坐标改变就相应的函数,求解答!

virtual QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)

例如:

 QVariant Component::itemChange(GraphicsItemChange change, const QVariant &value)
  {
      if (change == ItemPositionChange && scene()) {
          // value is the new position.
          QPointF newPos = value.toPointF();
          QRectF rect = scene()->sceneRect();
          if (!rect.contains(newPos)) {
              // Keep the item inside the scene rect.
              newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())));
              newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())));
              return newPos;
          }
      }
      return QGraphicsItem::itemChange(change, value);
  }