diff --git a/examples/opengl/overpainting/glwidget.cpp b/examples/opengl/overpainting/glwidget.cpp
index 78f5f96c484213f3a6a1d094eeec661bacd2f7f1..420ae3e88140d62905a955990463b78e70c5f2fb 100644
--- a/examples/opengl/overpainting/glwidget.cpp
+++ b/examples/opengl/overpainting/glwidget.cpp
@@ -161,7 +161,8 @@ void GLWidget::paintEvent(QPaintEvent *event)
     static GLfloat lightPosition[4] = { 0.5, 5.0, 7.0, 1.0 };
     glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
 
-    setupViewport(width(), height());
+    qreal pixelRatio = devicePixelRatio();
+    setupViewport(width() * pixelRatio, height() * pixelRatio);
 //! [6]
 
 //! [7]
@@ -200,7 +201,8 @@ void GLWidget::paintEvent(QPaintEvent *event)
 //! [11]
 void GLWidget::resizeGL(int width, int height)
 {
-    setupViewport(width, height);
+    qreal pixelRatio = devicePixelRatio();
+    setupViewport(width*pixelRatio, height*pixelRatio);
 }
 //! [11]