0
votes

I have a custom QGraphicsScene in which I have a mouseMoveEvent(QGraphicsSceneMouseEvent *event);

When I hover on the scene with the mouse, the mouseMoveEvent gets properly fired.
However when I hover with a mouse button pressed, then it does not get fired anymore. This is how I setup the whole scene in the main window:

scene = new NodeScene(this);  -> My Custom QGraphicsScene class
scene->setSceneRect(QRectF(0, 0, 5000, 5000));

QHBoxLayout *layout = new QHBoxLayout;
view = new QGraphicsView(scene);
layout->addWidget(view);
view->setDragMode(QGraphicsView::RubberBandDrag);
view->setMouseTracking(true);

QWidget *widget = new QWidget;
widget->setLayout(layout);
setCentralWidget(widget);
scene->setCentralWidget(widget);

And here is the code where I do handle mouse events (it's for Maya execution):

void NodeScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    MGlobal::displayInfo("Move");
    QGraphicsScene::mouseMoveEvent(event);
}

void NodeScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    MGlobal::displayInfo("Press");
    QGraphicsScene::mousePressEvent(event);
}

void NodeScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
    MGlobal::displayInfo("Release");
    QGraphicsScene::mouseReleaseEvent(event);
}

Any idea how I can get the mouseMoveEvents even when a mouse button is pressed ?

2

2 Answers

1
votes

It sounds like you're not implementing all of the mouse events, just the mouseMoveEvent.

When overriding a mouse event, you should handle all of them (move, press and release events).

You can then set a boolean in the press event to know whether or not the mouse button is held down when entering the mouseMove event.

0
votes

Found the issue by comparing my code to other examples, and it is due to the setDragMode(QGraphicsView::RubberBandDrag); line. The code should by default be on QGraphicsView::NoDrag and the RubberBandDrag be enabled only upon press.