You are not logged in.

Dear visitor, welcome to QtForum.org. 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.

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