Hi Qt experts,
I can not capture the expected mouse move event from GraphicsItem::sceneEvent().
I rewrite David w drell's code of "Example of re-sizing a QGraphicsItem using Mouse events."
The class StateBox inherits from QGraphicsPixmapItem and install the corner members that users can drag the corner to to-size the item.
These corners have been installed and sceneEventFilter() watch them.
class Corner : public QGraphicsItem {..}
class StateBox : public QGraphicsPixmapItem { .. Corner* _corners[8]; ..};
void StateBox::hoverEnterEvent(QGraphicsSceneHoverEvent *) {
.. _corners[i]->installSceneEventFilter(this); ..} // then item can watch corner event
in the event watch filter - sceneEventFilter(QGraphicsItem *watched, QEvent* event),
I monitor the mouse movement of the corner in the StateBox's coordinate
Corner *corner = dynamic_cast<Corner*>(watched);
...
QGraphicsSceneMouseEvent * mevent
= dynamic_cast<QGraphicsSceneMouseEvent*>(event);
if (event->type() == QEvent::GraphicsSceneMouseMove)
// dump mevemt->pos();
However, the mouse movement is very strange ..
If I drag the bottom-right corner, the position seems located on StateBox's coordinate and corner's coordinate.
Is it a normal behavior ?
How can I get the corner's position always in StateBox's ?
this is my code link
StateBox StateBox
this is the mouse moving data form corner 2 (the right-bottom corner)
example2.png
" QEvent == 156" corner 2 mousedown QPointF(1, 3) // ? corner' coordinate ?
" QEvent == 155" corner 2 move QPointF(2, 3) // ? corner's coordinate ?
" QEvent == 155" corner 2 move QPointF(88, 89) // statebox's coordinate
" QEvent == 155" corner 2 move QPointF(4, 4) // ? corner's coordinate ?
" QEvent == 155" corner 2 move QPointF(90, 90) // statebox's coordinate
" QEvent == 155" corner 2 move QPointF(6, 7)
" QEvent == 155" corner 2 move QPointF(91, 91)
" QEvent == 155" corner 2 move QPointF(8, 8)
" QEvent == 155" corner 2 move QPointF(93, 92)
Can you help ? Thank you very much.
Bookmarks