Qt QOpenGLWidget wheelEvent奇怪的行为 [英] Qt QOpenGLWidget wheelEvent strange behaviour

查看:54
本文介绍了Qt QOpenGLWidget wheelEvent奇怪的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下课程:

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;

};

我想使用wheelEvent放大/缩小场景.

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

这是代码:

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.

此代码可用于我实现的所有其他小部件(QGraphicsView等).我想知道QOpenGLWidget上是否有什么特别的事情要做?

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 ?

我无法解释这种行为...如果有帮助,我正在研究Ubuntu 14.04 LTS

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

推荐答案

我确实遇到了同样的问题.

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.

qoglwidget的更新事件和鼠标移动事件在事件循环中的优先级可能比转轮事件的优先级高.轮盘事件似乎并没有被丢弃,而是被累积起来并与下一个通过"事件一起到达.

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.

这篇关于Qt QOpenGLWidget wheelEvent奇怪的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆