You are not logged in.

1

Wednesday, April 18th 2007, 9:43pm

QGraphicsSceneMouseEvent * event has no value

Hi,

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();
QGraphicsScene::mousePressEvent(event);
}

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 {
Q_OBJECT
public:
GraphWidget(QGraphicsView *view);
~GraphWidget();
void addObject(Item *item, double angle);
protected:
void mousePressEvent ( QGraphicsSceneMouseEvent * event );
private:
};

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

Anything I ve done wrong or I forgot?

Thank for your help

2

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