Qt - How to get mouse events on Qt3DWindow

后端 未结 2 1976
清歌不尽
清歌不尽 2020-12-22 02:50

I want to get mouse events (like mouse position) on a Qt3D Window, every time I click inside the window.

I\'ve seen this question (also the same question on this for

2条回答
  •  感情败类
    2020-12-22 03:18

    Normally the "mouseMoveEvent" is bind with a Qwidget.

    This is the source code of Qt3DInput::QmouseEvent:

    class QT3DINPUTSHARED_EXPORT QMouseEvent : public QObject {
        Q_OBJECT 
    private:
        QT_PREPEND_NAMESPACE(QMouseEvent) m_event;  
    };
    

    m_event has already contained the information of your mouse and it should be automatically processed.

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

    So, I don't think you need to create a new Qt3DInput::QMouseDevice. And you shouldn't do Qt3DInput::QMouseEvent *e; since the widget will get it automatically.

    I don't know how to use mouseEvent without overriding it inside of a Qwidget, and Qt3DExtras::Qt3DWindow view should contain a default mouseMoveEvent(). If you just want to print out an "ok", I suggest you don't write anything about mouseMoveEvent(). If you hope something happens when your mouse is moving, you should override view's mouseMoveEvent().

提交回复
热议问题