2
votes

I have the following class :

class Curve2DOpenGLWidget : public QOpenGLWidget, protected QOpenGLFunctions_3_3_Core {
Q_OBJECT   
public:

    Curve2DOpenGLWidget( QWidget* parent = nullptr );
    ~Curve2DOpenGLWidget();  

    void initializeGL() override;
    void resizeGL(int width, int height) override;
    void paintGL() override;
    void NativePaintGL();

protected:
    void mousePressEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void wheelEvent(QWheelEvent *event) override;

};

I want to use wheelEvent to zoom in / zoom out in my scene.

Here is the code :

void Curve2DOpenGLWidget::wheelEvent( QWheelEvent* event ) {
    QOpenGLWidget::wheelEvent(event);
    float numStep = (event->angleDelta().y() / 8) / 15;
    m_camera.MoveFront(numStep * 0.1f);
}

It does what I want, but this event is not called when I move the mouse and use mouse wheel at the same time.

This code works on all the other widgets I've implemented (QGraphicsView, etc.). I'm wondering if there is anything special to do on QOpenGLWidget ?

I can't explain this behaviour... If it can help, I'm working on Ubuntu 14.04 LTS

3

3 Answers

1
votes

I did run into the same problem.

In my case it was a QTimer based render loop which was updating 4 QOpenGLWidgets and the window’s title bar (which was actually pretty CPU intensive) at 100 FPS.
It didn’t manifest on Windows, but on Linux.

The update events for the qoglwidgets and the mouse move events probably have higher priority in the event loop than the wheel events. The wheel events don’t seem to be dropped but are accumulated and arrive together with next event that »gets through«.

Luckily the use case allowed to replace this render loop with an event driven implementation avoiding this issue.

1
votes

See Qt::AA_CompressHighFrequencyEvents and Qt::AA_CompressTabletEvents in http://doc.qt.io/qt-5/qt.html#ApplicationAttribute-enum

These are new attributes in Qt 5.

0
votes

From Qt documentation

Mouse events occur when a mouse button is pressed or released inside a widget, or when the mouse cursor is moved.

Mouse move events will occur only when a mouse button is pressed down, unless mouse tracking has been enabled with QWidget::setMouseTracking().

So you need setMouseTracking(true) in your constructor