Mouse controls over Qt 3D Window

空扰寡人 提交于 2019-12-02 10:11:58

问题


I have a QWidget containing a Qt3DWindow(). I'd like to be able to "zoom" in and out on a QtEntity, within the Qt3DWindow, using the mouse scroll wheel, while hovering over the window.

I have the functionality working, but only when hovering the mouse outside of the Qt3DWindow frame. Here's my code for initializing the window and processing mouse wheel events.

Window Initialization:

mainView = new Qt3DExtras::Qt3DWindow();
mainView->defaultFramegraph()->setClearColor(QColor(QRgb(0x4d4d4f)));

QWidget *container = QWidget::createWindowContainer(mainView);

Processing wheel events:

void ModelView::wheelEvent(QWheelEvent *event){

    QVector3D vec;

    vec = cameraEntity->position() - modifier->m_transform->translation();

    vec = vec.normalized();

    QPoint delta = event->angleDelta();

    int zoom_distance = delta.y()*0.01;

    vec = cameraEntity->position() - zoom_distance*vec;

    cameraEntity->setPosition(vec);
}

What's the trick for overriding the window's mouse grab when hovering over the Qt3DWindow frame?

Thanks in advance for any help.


回答1:


I'd recommend using an event filter to intercept the Qt3DWindow events. Your ModelView class can install itself as an event filter on the Qt3DWindow, detect wheel events, handle them itself, and return true to indicate that they're handled. For all other events, return false, and the Qt3DWindow will receive and process them normally.

Look at QObject::installEventfilter and QObject::eventFilter methods in the docs.



来源:https://stackoverflow.com/questions/41986164/mouse-controls-over-qt-3d-window

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!