2020#include < AIS_Shape.hxx>
2121#include < AIS_ViewCube.hxx>
2222#include < Aspect_DisplayConnection.hxx>
23- #include < Aspect_NeutralWindow.hxx>
2423#include < BRepPrimAPI_MakeBox.hxx>
2524#include < Message.hxx>
2625#include < OpenGl_GraphicDriver.hxx>
@@ -78,7 +77,7 @@ OcctQOpenGLWidgetViewer::OcctQOpenGLWidgetViewer(QWidget* theParent)
7877 Graphic3d_RenderingParams::PerfCounters_FrameRate | Graphic3d_RenderingParams::PerfCounters_Triangles);
7978
8079 // Qt widget setup
81- setAttribute (Qt::WA_AcceptTouchEvents); // necessary to recieve QTouchEvent events
80+ setAttribute (Qt::WA_AcceptTouchEvents); // necessary to receive QTouchEvent events
8281 setMouseTracking (true );
8382 setBackgroundRole (QPalette::NoRole); // or NoBackground
8483 setFocusPolicy (Qt::StrongFocus); // set focus policy to threat QContextMenuEvent from keyboard
@@ -150,13 +149,14 @@ void OcctQOpenGLWidgetViewer::initializeGL()
150149 const Graphic3d_Vec2i aViewSize (rect ().right () - rect ().left (), rect ().bottom () - rect ().top ());
151150
152151 const bool isFirstInit = myView->Window ().IsNull ();
153- if (!OcctGlTools::InitializeGlWindow (myView, aNativeWin, aViewSize))
152+ if (!OcctGlTools::InitializeGlWindow (myView, aNativeWin, aViewSize, devicePixelRatioF () ))
154153 {
155154 QMessageBox::critical (0 , " Failure" , " OpenGl_Context is unable to wrap OpenGL context" );
156155 QApplication::exit (1 );
157156 return ;
158157 }
159158
159+ makeCurrent (); // restore Qt framebuffer
160160 dumpGlInfo (true , true );
161161 if (isFirstInit)
162162 {
@@ -188,7 +188,8 @@ bool OcctQOpenGLWidgetViewer::event(QEvent* theEvent)
188188 for (const QTouchEvent::TouchPoint& aQTouch : aQTouchEvent->touchPoints ())
189189 {
190190 const Standard_Size aTouchId = aQTouch.id ();
191- const Graphic3d_Vec2d aNewPos2d (aQTouch.pos ().x (), aQTouch.pos ().y ());
191+ const Graphic3d_Vec2d aNewPos2d =
192+ myView->Window ()->ConvertPointToBacking (Graphic3d_Vec2d (aQTouch.pos ().x (), aQTouch.pos ().y ()));
192193 const Graphic3d_Vec2i aNewPos2i = Graphic3d_Vec2i (aNewPos2d + Graphic3d_Vec2d (0.5 ));
193194 if (aQTouch.state () == Qt::TouchPointPressed
194195 && aNewPos2i.minComp () >= 0 )
@@ -262,10 +263,11 @@ void OcctQOpenGLWidgetViewer::mousePressEvent(QMouseEvent* theEvent)
262263 return ; // skip mouse events emulated by system from screen touches
263264
264265 theEvent->accept ();
265- const Graphic3d_Vec2i aPnt (theEvent->pos ().x (), theEvent->pos ().y ());
266+ const Graphic3d_Vec2d aPnt2d (theEvent->pos ().x (), theEvent->pos ().y ());
267+ const Graphic3d_Vec2i aPnt2i (myView->Window ()->ConvertPointToBacking (aPnt2d) + Graphic3d_Vec2d (0.5 ));
266268 const Aspect_VKeyMouse aButtons = OcctQtTools::qtMouseButtons2VKeys (theEvent->buttons ());
267269 const Aspect_VKeyFlags aFlags = OcctQtTools::qtMouseModifiers2VKeys (theEvent->modifiers ());
268- if (AIS_ViewController::UpdateMouseButtons (aPnt , aButtons, aFlags, false ))
270+ if (AIS_ViewController::UpdateMouseButtons (aPnt2i , aButtons, aFlags, false ))
269271 updateView ();
270272}
271273
@@ -279,10 +281,11 @@ void OcctQOpenGLWidgetViewer::mouseReleaseEvent(QMouseEvent* theEvent)
279281 return ;
280282
281283 theEvent->accept ();
282- const Graphic3d_Vec2i aPnt (theEvent->pos ().x (), theEvent->pos ().y ());
284+ const Graphic3d_Vec2d aPnt2d (theEvent->pos ().x (), theEvent->pos ().y ());
285+ const Graphic3d_Vec2i aPnt2i (myView->Window ()->ConvertPointToBacking (aPnt2d) + Graphic3d_Vec2d (0.5 ));
283286 const Aspect_VKeyMouse aButtons = OcctQtTools::qtMouseButtons2VKeys (theEvent->buttons ());
284287 const Aspect_VKeyFlags aFlags = OcctQtTools::qtMouseModifiers2VKeys (theEvent->modifiers ());
285- if (AIS_ViewController::UpdateMouseButtons (aPnt , aButtons, aFlags, false ))
288+ if (AIS_ViewController::UpdateMouseButtons (aPnt2i , aButtons, aFlags, false ))
286289 updateView ();
287290}
288291
@@ -299,10 +302,11 @@ void OcctQOpenGLWidgetViewer::mouseMoveEvent(QMouseEvent* theEvent)
299302 return ; // skip mouse events emulated by system from screen touches
300303
301304 theEvent->accept ();
302- const Graphic3d_Vec2i aNewPos (theEvent->pos ().x (), theEvent->pos ().y ());
305+ const Graphic3d_Vec2d aPnt2d (theEvent->pos ().x (), theEvent->pos ().y ());
306+ const Graphic3d_Vec2i aPnt2i (myView->Window ()->ConvertPointToBacking (aPnt2d) + Graphic3d_Vec2d (0.5 ));
303307 const Aspect_VKeyMouse aButtons = OcctQtTools::qtMouseButtons2VKeys (theEvent->buttons ());
304308 const Aspect_VKeyFlags aFlags = OcctQtTools::qtMouseModifiers2VKeys (theEvent->modifiers ());
305- if (AIS_ViewController::UpdateMousePosition (aNewPos , aButtons, aFlags, false ))
309+ if (AIS_ViewController::UpdateMousePosition (aPnt2i , aButtons, aFlags, false ))
306310 updateView ();
307311}
308312
@@ -317,15 +321,16 @@ void OcctQOpenGLWidgetViewer::wheelEvent(QWheelEvent* theEvent)
317321
318322 theEvent->accept ();
319323#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
320- const Graphic3d_Vec2i aPos ( Graphic3d_Vec2d ( theEvent->position ().x (), theEvent->position ().y () ));
324+ const Graphic3d_Vec2d aPnt2d ( theEvent->position ().x (), theEvent->position ().y ());
321325#else
322- const Graphic3d_Vec2i aPos (theEvent->pos ().x (), theEvent->pos ().y ());
326+ const Graphic3d_Vec2d aPnt2d (theEvent->pos ().x (), theEvent->pos ().y ());
323327#endif
328+ const Graphic3d_Vec2i aPnt2i (myView->Window ()->ConvertPointToBacking (aPnt2d) + Graphic3d_Vec2d (0.5 ));
324329
325330#if (OCC_VERSION_HEX >= 0x070700)
326331 if (!myView->Subviews ().IsEmpty ())
327332 {
328- Handle (V3d_View) aPickedView = myView->PickSubview (aPos );
333+ Handle (V3d_View) aPickedView = myView->PickSubview (aPnt2i );
329334 if (!aPickedView.IsNull () && aPickedView != myFocusView)
330335 {
331336 // switch input focus to another subview
@@ -336,7 +341,7 @@ void OcctQOpenGLWidgetViewer::wheelEvent(QWheelEvent* theEvent)
336341 }
337342#endif
338343
339- if (AIS_ViewController::UpdateZoom (Aspect_ScrollDelta (aPos , double (theEvent->angleDelta ().y ()) / 8.0 )))
344+ if (AIS_ViewController::UpdateZoom (Aspect_ScrollDelta (aPnt2i , double (theEvent->angleDelta ().y ()) / 8.0 )))
340345 updateView ();
341346}
342347
@@ -357,16 +362,19 @@ void OcctQOpenGLWidgetViewer::paintGL()
357362 if (myView.IsNull () || myView->Window ().IsNull ())
358363 return ;
359364
360- Graphic3d_Vec2i aViewSizeOld; myView->Window ()->Size (aViewSizeOld.x (), aViewSizeOld.y ());
361-
362- const Aspect_Drawable aNativeWin = OcctGlTools::GetGlNativeWindow ((Aspect_Drawable)winId ());
363- if (myView->Window ()->NativeHandle () != aNativeWin)
365+ const double aDevPixelRatioOld = myView->Window ()->DevicePixelRatio ();
366+ if (myView->Window ()->NativeHandle () != OcctGlTools::GetGlNativeWindow ((Aspect_Drawable)winId ()))
364367 {
365368 // workaround window recreation done by Qt on monitor (QScreen) disconnection
366369 Message::SendWarning () << " Native window handle has changed by QOpenGLWidget!" ;
367370 initializeGL ();
368- return ;
369371 }
372+ else if (devicePixelRatioF () != aDevPixelRatioOld)
373+ {
374+ initializeGL ();
375+ }
376+
377+ Graphic3d_Vec2i aViewSizeOld; myView->Window ()->Size (aViewSizeOld.x (), aViewSizeOld.y ());
370378
371379 // wrap FBO created by QOpenGLFramebufferObject
372380 if (!OcctGlTools::InitializeGlFbo (myView))
@@ -377,7 +385,7 @@ void OcctQOpenGLWidgetViewer::paintGL()
377385 }
378386
379387 Graphic3d_Vec2i aViewSizeNew; myView->Window ()->Size (aViewSizeNew.x (), aViewSizeNew.y ());
380- if (aViewSizeNew != aViewSizeOld)
388+ if (aViewSizeNew != aViewSizeOld || myView-> Window ()-> DevicePixelRatio () != aDevPixelRatioOld )
381389 dumpGlInfo (true , false );
382390
383391 // reset global GL state from Qt before redrawing OCCT
0 commit comments