Solved:How to implement lastScenePos()?
-
Hi...
according to Qt document:QPointF QGraphicsSceneMouseEvent::lastScenePos () const
Returns the last recorded mouse cursor position in scene coordinates. The last recorded position is the position of the previous mouse event received by the view that created the event.
I am not understand how to write it in application. Could you give me an example/suggestion how to write or implement this?
Thank you.
-
Yes, I mean how to use it because I try like this but the coordinate not detected, always zero. I use buttonDownScenePos
@
QPointF DialogApplication::get_koordinat_mouse_klik(){QPointF mouse_koordinat; QEvent::Type type; QGraphicsSceneMouseEvent mouseEvent(type); //mouse_koordinat = mouseEvent.lastScenePos(); mouse_koordinat= mouseEvent.buttonDownScenePos(Qt::LeftButton); return mouse_koordinat;
}
@ -
I think it's better to use QGraphicsSceneMouseEvent::lastScenePos() inside one of those methods of the QGraphicsScene class :
@
virtual void mouseDoubleClickEvent ( QGraphicsSceneMouseEvent * mouseEvent )
virtual void mouseMoveEvent ( QGraphicsSceneMouseEvent * mouseEvent )
virtual void mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent )
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * mouseEvent )
@so you have to reimplement them !
-
Thank you very much issam and rcari. It's done well:
@
void MyItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if(event->button()==Qt::LeftButton){
myMouse_koordinat = event->buttonDownScenePos
(Qt::LeftButton);
qDebug() << myMouse_koordinat.x();
}
update();
QGraphicsItem::mousePressEvent(event);
}
@