mouseMoveEvent in QGraphicsItem
Dear All,
I have re-implemented mouseMoveEvent(QGraphicsSceneMouseEvent *event) in my class which is derived from QGraphicsItem. When i draw an item on scene and move the mouse cursor inside the item, mouseMoveEvent() will not trigger. It will only trigger when i click on the item and move the mouse inside the item (i.e leftclick + move). I have set the setAcceptHoverEvents(true). But still mouseMoveEvent() event doesn't trigger. Can anyone tell how can i resolve this problem such that, mouse move on item trigger mouseMoveEvent(). Following is my code
Code:
{
m_Rectangle.setSize(size);
m_Rectangle.moveTopLeft(center);
setZValue(((int)m_Rectangle.top() + (int)m_Rectangle.left())% 2);
setFlags(ItemIsSelectable | ItemIsMovable);
setAcceptHoverEvents(true);
}
CMyItem::~CMyItem()
{
}
QRectF CMyItem
::boundingRect() const {
return QRectF(0,
0,
200,
100);
}
{
path.addRect(0, 0, 200, 100);
return path;
}
{
Q_UNUSED(widget);
//QBrush brush(
pen.setColor(Qt::black);
painter->setPen(pen);
painter->drawRect(m_Rectangle);
}
{
update();
event->accept();
}
{
}
{
update();
}
Re: mouseMoveEvent in QGraphicsItem
Any answer for this please????
Re: mouseMoveEvent in QGraphicsItem
Enable mouse tracking for the view's viewport.
Re: mouseMoveEvent in QGraphicsItem
Hi,
this problem was discussed couple of times before in the forum. For example the following,
http://www.qtcentre.org/forum/f-qt-p...mouseMoveEvent
but I still got the same problem with it. So good luck:)
Re: mouseMoveEvent in QGraphicsItem
i have already used setMouseTracking() for view. but still its not working. In Qt Asistant i have checked description of setAcceptHoverEvents(). i.e.
Hover events are commonly used to highlight an item when it's entered, and for tracking the mouse cursor as it hovers over the item (equivalent to QWidget::mouseTracking).
But setAcceptHoverEvents() doesn't act exactly as setMouseTracking()
Re: mouseMoveEvent in QGraphicsItem
But why do you expect a hover event to trigger a mouse move event? It will trigger hoverMoveEvent()...
Re: mouseMoveEvent in QGraphicsItem
you are absolutely correct wysota. thank you very much. then i have misunderstood the QGraphicsItem mouseMoveEvent() with QWidget mouseMoveEvent(). Because mouseMoveEvent() itself will be trigger when user hover the mouse on widget.
My problem is solved. Thank you very much.