MouseMoveEvent when scrolling



  • Hi
    I was making some demo application when I realized I was getting mouseMoveEvents when scrolling. The position in the event is the last position of the mouse when it was released. I also made a small video documenting this visually. The code is for simulating waves by the way :D. But I moved the cursor away from the waves and scrolled you can see it generates disturbances in the waves. After a closer inspection I found out that they are getting called with the last position where the mouse was clicked. Is this a correct behaviour? If yes what is wrong with my code(I don't want to get mouse move events when scrolling... Is it a feature or a bug?)?

    class MyGraphicsScene : public QGraphicsScene
    {
    Q_OBJECT
    signals:
    void mouseMoved(QPointF);
    private:
    void	mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent);
    };
    
    void MyGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
    {
    emit mouseMoved(mouseEvent->scenePos());
    mouseEvent->accept(); // Actually I don't know if I should do this, but it doesn't affect this behaviour
    }
    
    
    class Wave1DWidget : public QGraphicsView
    {
    Q_OBJECT
    ...
    MyGraphicsScene scene;
    public slots:
    void sceneMouseMoved(QPointF);
    ...
    }
    
    Wave1DWidget constructor{
    ...
    connect(&scene,SIGNAL(mouseMoved(QPointF)),this,SLOT(sceneMouseMoved(QPointF)));
    ...
    }
    
    void Wave1DWidget::sceneMouseMoved(QPointF pos)
    {
    cout <<pos.x() << ", " << pos.y() << endl;
    ... // handling the move event like setting the height of the wave at that point…
    }
    

    [Edit: added missing coding tags: ```before and after the code SGaist]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.