如何获取Qt3DWindow的事件

如何获取Qt3DWindow的事件? 继承Qt3DWindow并在子类里重载监听事件的代码。
举例如下:

my3dwindow.h

#ifndef MY3DWINDOW_H
#define MY3DWINDOW_H

#include 

class My3DWindow: public Qt3DExtras::Qt3DWindow
{
    Q_OBJECT
public:
    My3DWindow(QScreen *screen = nullptr);
    ~My3DWindow();

protected:

    void keyPressEvent(QKeyEvent *ev);
};

#endif // MY3DWINDOW_H

my3dwindow.cpp

#include "my3dwindow.h"
#include 
#include 

My3DWindow::My3DWindow(QScreen *screen):Qt3DExtras::Qt3DWindow(screen)
{

}

My3DWindow::~My3DWindow()
{

}

void My3DWindow::keyPressEvent(QKeyEvent *ev)
{
    switch (ev->key()) {
    case Qt::Key_W:
        qDebug()<<"Key is pressed";
        break;
    default:
        break;
    }
}

main.cpp

#include "my3dwindow.h"

int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    My3DWindow *view = new My3DWindow();
    view->defaultFrameGraph()->setClearColor(QColor(QRgb(0x4d4d4f)));
    QWidget *sceneContainer = QWidget::createWindowContainer(view); 
}

你可能感兴趣的:(Qt)