First ,let me explain what problem I have countered.
I use QGraphicsView Frame.I create a class Cordinate which inherits from QGraphicsItem.This class's main work is to draw a Cordinate System.
Now I want to track mouse postion in this cordinate system. While I implement mouseMoveEvent(QGraphicsSceneMouseEvent * event), and
mousePressEvent(QGraphicsSceneMouseEvent * event) in this Cordinate class. And here is my code :
{
float x = event->pos().x;
qDebug() << "mouse move " << endl;
}
{
qDebug()<<"mouse press point is ("<< point.x() <<", "<<point.y()<<")"<<endl;
}
void Cordinate::mouseMoveEvent(QGraphicsSceneMouseEvent * event)
{
QGraphicsItem::mouseMoveEvent(event);
float x = event->pos().x;
qDebug() << "mouse move " << endl;
}
void Cordinate::mousePressEvent(QGraphicsSceneMouseEvent * event)
{
QGraphicsItem::mousePressEvent(event);
QPointF point = event->pos();
qDebug()<<"mouse press point is ("<< point.x() <<", "<<point.y()<<")"<<endl;
}
To copy to clipboard, switch view to plain text mode
And when run, the console print out the mouse press point ,but doesn't print out the mouse move?
Why?Doesn's the item grab the mouse move event? And how I can work out this problem?
Wish your help, please! Thank you very much!
Oh, last and the most ,I have another class which is Cordinate class's child item!
Bookmarks