2121#include < AIS_Shape.hxx>
2222#include < AIS_ViewCube.hxx>
2323#include < Aspect_DisplayConnection.hxx>
24- #include < Aspect_NeutralWindow.hxx>
2524#include < BRepPrimAPI_MakeBox.hxx>
2625#include < Message.hxx>
2726#include < OpenGl_GraphicDriver.hxx>
@@ -166,7 +165,8 @@ bool OcctQQuickFramebufferViewer::event(QEvent* theEvent)
166165 for (const QTouchEvent::TouchPoint& aQTouch : aQTouchEvent->touchPoints ())
167166 {
168167 const Standard_Size aTouchId = aQTouch.id ();
169- const Graphic3d_Vec2d aNewPos2d (aQTouch.pos ().x (), aQTouch.pos ().y ());
168+ const Graphic3d_Vec2d aNewPos2d =
169+ myView->Window ()->ConvertPointToBacking (Graphic3d_Vec2d (aQTouch.pos ().x (), aQTouch.pos ().y ()));
170170 const Graphic3d_Vec2i aNewPos2i = Graphic3d_Vec2i (aNewPos2d + Graphic3d_Vec2d (0.5 ));
171171 if (aQTouch.state () == Qt::TouchPointPressed
172172 && aNewPos2i.minComp () >= 0 )
@@ -237,10 +237,11 @@ void OcctQQuickFramebufferViewer::mousePressEvent(QMouseEvent* theEvent)
237237 return ; // skip mouse events emulated by system from screen touches
238238
239239 theEvent->accept ();
240- const Graphic3d_Vec2i aPnt (theEvent->pos ().x (), theEvent->pos ().y ());
240+ const Graphic3d_Vec2d aPnt2d (theEvent->pos ().x (), theEvent->pos ().y ());
241+ const Graphic3d_Vec2i aPnt2i (myView->Window ()->ConvertPointToBacking (aPnt2d) + Graphic3d_Vec2d (0.5 ));
241242 const Aspect_VKeyMouse aButtons = OcctQtTools::qtMouseButtons2VKeys (theEvent->buttons ());
242243 const Aspect_VKeyFlags aFlags = OcctQtTools::qtMouseModifiers2VKeys (theEvent->modifiers ());
243- if (AIS_ViewController::UpdateMouseButtons (aPnt , aButtons, aFlags, false ))
244+ if (AIS_ViewController::UpdateMouseButtons (aPnt2i , aButtons, aFlags, false ))
244245 updateView ();
245246}
246247
@@ -254,10 +255,11 @@ void OcctQQuickFramebufferViewer::mouseReleaseEvent(QMouseEvent* theEvent)
254255 return ;
255256
256257 theEvent->accept ();
257- const Graphic3d_Vec2i aPnt (theEvent->pos ().x (), theEvent->pos ().y ());
258+ const Graphic3d_Vec2d aPnt2d (theEvent->pos ().x (), theEvent->pos ().y ());
259+ const Graphic3d_Vec2i aPnt2i (myView->Window ()->ConvertPointToBacking (aPnt2d) + Graphic3d_Vec2d (0.5 ));
258260 const Aspect_VKeyMouse aButtons = OcctQtTools::qtMouseButtons2VKeys (theEvent->buttons ());
259261 const Aspect_VKeyFlags aFlags = OcctQtTools::qtMouseModifiers2VKeys (theEvent->modifiers ());
260- if (AIS_ViewController::UpdateMouseButtons (aPnt , aButtons, aFlags, false ))
262+ if (AIS_ViewController::UpdateMouseButtons (aPnt2i , aButtons, aFlags, false ))
261263 updateView ();
262264
263265 // take keyboard focus on mouse click
@@ -277,10 +279,11 @@ void OcctQQuickFramebufferViewer::mouseMoveEvent(QMouseEvent* theEvent)
277279 return ; // skip mouse events emulated by system from screen touches
278280
279281 theEvent->accept ();
280- const Graphic3d_Vec2i aNewPos (theEvent->pos ().x (), theEvent->pos ().y ());
282+ const Graphic3d_Vec2d aPnt2d (theEvent->pos ().x (), theEvent->pos ().y ());
283+ const Graphic3d_Vec2i aPnt2i (myView->Window ()->ConvertPointToBacking (aPnt2d) + Graphic3d_Vec2d (0.5 ));
281284 const Aspect_VKeyMouse aButtons = OcctQtTools::qtMouseButtons2VKeys (theEvent->buttons ());
282285 const Aspect_VKeyFlags aFlags = OcctQtTools::qtMouseModifiers2VKeys (theEvent->modifiers ());
283- if (AIS_ViewController::UpdateMousePosition (aNewPos , aButtons, aFlags, false ))
286+ if (AIS_ViewController::UpdateMousePosition (aPnt2i , aButtons, aFlags, false ))
284287 updateView ();
285288}
286289
@@ -295,11 +298,12 @@ void OcctQQuickFramebufferViewer::wheelEvent(QWheelEvent* theEvent)
295298
296299 theEvent->accept ();
297300#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
298- const Graphic3d_Vec2i aPos ( Graphic3d_Vec2d ( theEvent->position ().x (), theEvent->position ().y () ));
301+ const Graphic3d_Vec2d aPnt2d ( theEvent->position ().x (), theEvent->position ().y ());
299302#else
300- const Graphic3d_Vec2i aPos (theEvent->pos ().x (), theEvent->pos ().y ());
303+ const Graphic3d_Vec2d aPnt2d (theEvent->pos ().x (), theEvent->pos ().y ());
301304#endif
302- if (AIS_ViewController::UpdateZoom (Aspect_ScrollDelta (aPos, double (theEvent->angleDelta ().y ()) / 8.0 )))
305+ const Graphic3d_Vec2i aPnt2i (myView->Window ()->ConvertPointToBacking (aPnt2d) + Graphic3d_Vec2d (0.5 ));
306+ if (AIS_ViewController::UpdateZoom (Aspect_ScrollDelta (aPnt2i, double (theEvent->angleDelta ().y ()) / 8.0 )))
303307 updateView ();
304308}
305309
@@ -337,10 +341,11 @@ void OcctQQuickFramebufferViewer::hoverMoveEvent(QHoverEvent* theEvent)
337341 return ;
338342
339343 theEvent->accept ();
340- const Graphic3d_Vec2i aNewPos (theEvent->pos ().x (), theEvent->pos ().y ());
344+ const Graphic3d_Vec2d aPnt2d (theEvent->pos ().x (), theEvent->pos ().y ());
345+ const Graphic3d_Vec2i aPnt2i (myView->Window ()->ConvertPointToBacking (aPnt2d) + Graphic3d_Vec2d (0.5 ));
341346 const Aspect_VKeyMouse aButtons = Aspect_VKeyMouse_NONE;
342347 const Aspect_VKeyFlags aFlags = OcctQtTools::qtMouseModifiers2VKeys (theEvent->modifiers ());
343- if (AIS_ViewController::UpdateMousePosition (aNewPos , aButtons, aFlags, false ))
348+ if (AIS_ViewController::UpdateMousePosition (aPnt2i , aButtons, aFlags, false ))
344349 updateView ();
345350}
346351
@@ -463,7 +468,7 @@ void OcctQQuickFramebufferViewer::initializeGL(QOpenGLFramebufferObject* theFbo)
463468 const Graphic3d_Vec2i aViewSize (theFbo->size ().width (), theFbo->size ().height ());
464469
465470 const bool isFirstInit = myView->Window ().IsNull ();
466- if (!OcctGlTools::InitializeGlWindow (myView, aNativeWin, aViewSize))
471+ if (!OcctGlTools::InitializeGlWindow (myView, aNativeWin, aViewSize, aQWindow-> devicePixelRatio () ))
467472 {
468473 Q_EMIT glCriticalError (" OpenGl_Context is unable to wrap OpenGL context" );
469474 return ;
@@ -506,16 +511,17 @@ void OcctQQuickFramebufferViewer::render(QOpenGLFramebufferObject* theFbo)
506511 }
507512
508513 Graphic3d_Vec2i aViewSizeOld; myView->Window ()->Size (aViewSizeOld.x (), aViewSizeOld.y ());
514+ const double aDevPixelRatioOld = myView->Window ()->DevicePixelRatio ();
509515
510516 // wrap FBO created by QOpenGLFramebufferObject
511- if (!OcctGlTools::InitializeGlFbo (myView))
517+ if (!OcctGlTools::InitializeGlFbo (myView, aQWindow-> devicePixelRatio () ))
512518 {
513519 Q_EMIT glCriticalError (" Default FBO wrapper creation failed" );
514520 return ;
515521 }
516522
517523 Graphic3d_Vec2i aViewSizeNew; myView->Window ()->Size (aViewSizeNew.x (), aViewSizeNew.y ());
518- if (aViewSizeNew != aViewSizeOld)
524+ if (aViewSizeNew != aViewSizeOld || myView-> Window ()-> DevicePixelRatio () != aDevPixelRatioOld )
519525 dumpGlInfo (true , false );
520526
521527 // reset global GL state from Qt before redrawing OCCT
0 commit comments