Hi!

I have subclassed QGraphicsItem class in order to create my own custom item. The following are the basic reimplemented functions.

Qt Code:
  1. QSampleItem::QSampleItem(QPointF p, QGraphicsItem *parent)
  2. : QGraphicsItem(parent),
  3. m_size(QSize(DEFAULT_WIDTH, DEFAULT_HEIGHT))
  4. {
  5. setPos(p);
  6.  
  7. setFlag(QGraphicsItem::ItemIsSelectable, true);
  8. setFlag(QGraphicsItem::ItemIsMovable, true);
  9. setAcceptHoverEvents(true);
  10. setAcceptDrops(true);
  11. }
  12.  
  13. QRectF QSampleItem::boundingRect() const
  14. {
  15. return QRectF(0, 0,
  16. m_size.width() + RESIZE_HANDLE_WIDTH,
  17. m_size.height() + RESIZE_HANDLE_HEIGHT);
  18. }
  19.  
  20. void QSampleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
  21. QWidget *widget)
  22. {
  23. Q_UNUSED(option);
  24. Q_UNUSED(widget);
  25.  
  26. painter->drawRoundedRect(RESIZE_HANDLE_WIDTH/2,
  27. RESIZE_HANDLE_HEIGHT/2,
  28. m_size.width(),
  29. m_size.height(),
  30. 5, 5);
  31. }
To copy to clipboard, switch view to plain text mode 

I have not re-implemented QGraphicsScene's mouse event functions. In the class above I need to reimplement the mouse event functions so that I can resize the shape from different directions and also move around.

But the none of following mouse event functions are called in my class.

Qt Code:
  1. void QSampleItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
  2. {
  3. qDebug()<<"Inside mousePressEvent";
  4. m_mousePressPoint = event->scenePos().toPoint();
  5.  
  6. QGraphicsItem::mousePressEvent(event);
  7. }
  8.  
  9. void QSampleItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
  10. {
  11. qDebug()<<"Inside mouseMoveEvent";
  12.  
  13. QGraphicsItem::mouseMoveEvent(event);
  14. }
  15.  
  16. void QSampleItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
  17. {
  18. m_mousePressPoint = QPoint(-1, -1);
  19.  
  20. QGraphicsItem::mouseReleaseEvent(event);
  21. }
To copy to clipboard, switch view to plain text mode 

I have reimplemented the hoverMoveEvent and it works fine.

Any idea why the mouse events are not called?

Thanks