Mouse controls Qt 3D Window

I have a QWidget containing Qt3DWindow (). I would like to be able to β€œscale” in QtEntity, in Qt3DWindow, using the mouse scroll wheel above the window.

I have functionality, but only when hovering the mouse outside the Qt3DWindow framework. Here is my code to initialize a window and handle mouse wheel events.

Window initialization:

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

Wheel event handling:

 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 is the trick to overriding the capture of the mouse window when you hover over the Qt3DWindow frame?

Thanks in advance for your help.

0
qt qt3d
source share
1 answer

I would recommend using an event filter to intercept Qt3DWindow events. Your ModelView class can set itself as an event filter in Qt3DWindow, detect wheel events, process them yourself, and return true to indicate that they are being processed. For all other events, return false, and Qt3DWindow will receive and process them normally.

Take a look at the QObject :: installEventfilter and QObject :: eventFilter methods in the docs.

+1
source share

All Articles