munna
25th May 2009, 11:31
Hi!
I have subclassed QGraphicsItem class in order to create my own custom item. The following are the basic reimplemented functions.
QSampleItem::QSampleItem(QPointF p, QGraphicsItem *parent)
: QGraphicsItem(parent),
m_size(QSize(DEFAULT_WIDTH, DEFAULT_HEIGHT))
{
setPos(p);
setFlag(QGraphicsItem::ItemIsSelectable, true);
setFlag(QGraphicsItem::ItemIsMovable, true);
setAcceptHoverEvents(true);
setAcceptDrops(true);
}
QRectF QSampleItem::boundingRect() const
{
return QRectF(0, 0,
m_size.width() + RESIZE_HANDLE_WIDTH,
m_size.height() + RESIZE_HANDLE_HEIGHT);
}
void QSampleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->drawRoundedRect(RESIZE_HANDLE_WIDTH/2,
RESIZE_HANDLE_HEIGHT/2,
m_size.width(),
m_size.height(),
5, 5);
}
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.
void QSampleItem::mousePressEvent(QGraphicsSceneMouseEv ent *event)
{
qDebug()<<"Inside mousePressEvent";
m_mousePressPoint = event->scenePos().toPoint();
QGraphicsItem::mousePressEvent(event);
}
void QSampleItem::mouseMoveEvent(QGraphicsSceneMouseEve nt *event)
{
qDebug()<<"Inside mouseMoveEvent";
QGraphicsItem::mouseMoveEvent(event);
}
void QSampleItem::mouseReleaseEvent(QGraphicsSceneMouse Event *event)
{
m_mousePressPoint = QPoint(-1, -1);
QGraphicsItem::mouseReleaseEvent(event);
}
I have reimplemented the hoverMoveEvent and it works fine.
Any idea why the mouse events are not called?
Thanks
I have subclassed QGraphicsItem class in order to create my own custom item. The following are the basic reimplemented functions.
QSampleItem::QSampleItem(QPointF p, QGraphicsItem *parent)
: QGraphicsItem(parent),
m_size(QSize(DEFAULT_WIDTH, DEFAULT_HEIGHT))
{
setPos(p);
setFlag(QGraphicsItem::ItemIsSelectable, true);
setFlag(QGraphicsItem::ItemIsMovable, true);
setAcceptHoverEvents(true);
setAcceptDrops(true);
}
QRectF QSampleItem::boundingRect() const
{
return QRectF(0, 0,
m_size.width() + RESIZE_HANDLE_WIDTH,
m_size.height() + RESIZE_HANDLE_HEIGHT);
}
void QSampleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->drawRoundedRect(RESIZE_HANDLE_WIDTH/2,
RESIZE_HANDLE_HEIGHT/2,
m_size.width(),
m_size.height(),
5, 5);
}
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.
void QSampleItem::mousePressEvent(QGraphicsSceneMouseEv ent *event)
{
qDebug()<<"Inside mousePressEvent";
m_mousePressPoint = event->scenePos().toPoint();
QGraphicsItem::mousePressEvent(event);
}
void QSampleItem::mouseMoveEvent(QGraphicsSceneMouseEve nt *event)
{
qDebug()<<"Inside mouseMoveEvent";
QGraphicsItem::mouseMoveEvent(event);
}
void QSampleItem::mouseReleaseEvent(QGraphicsSceneMouse Event *event)
{
m_mousePressPoint = QPoint(-1, -1);
QGraphicsItem::mouseReleaseEvent(event);
}
I have reimplemented the hoverMoveEvent and it works fine.
Any idea why the mouse events are not called?
Thanks