You are not logged in.

Dear visitor, welcome to If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.


Wednesday, April 18th 2007, 9:43pm

QGraphicsSceneMouseEvent * event has no value


I am trying to use a mousePressEvent in a QGraphicsScene. The event occurs and is executed but event parameter has no value about the position of the mouse.
I try to display the coords of mousepoint if clicked.

void GraphWidget::mousePressEvent (QGraphicsSceneMouseEvent * event){
cout << "mousetest" << event->pos().x();

The result is always "mousetest 0".
If I try the same in a QGraphicsItem the mouse coords are given properly.

#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <QObject>
#include <item.h>
class GraphWidget : public QGraphicsScene {
GraphWidget(QGraphicsView *view);
void addObject(Item *item, double angle);
void mousePressEvent ( QGraphicsSceneMouseEvent * event );

Strange beauces it works in a QGraphicsItem and not in my QGraphicsScene

Anything I ve done wrong or I forgot?

Thank for your help


Thursday, April 19th 2007, 2:43pm

Found it
Have to use scenePos() instead of Pos(). The position of the mouse was simply calculated outside the scene