# QVTKOpenGLNativeWidget in QGraphicsView Causing White Screen in Qt 6.5.6

**URL:** https://discourse.vtk.org/t/qvtkopenglnativewidget-in-qgraphicsview-causing-white-screen-in-qt-6-5-6/14764
**Category:** Support
**Tags:** rendering, code
**Created:** [October 24, 2024, 5:51pm UTC](https://discourse.vtk.org/t/qvtkopenglnativewidget-in-qgraphicsview-causing-white-screen-in-qt-6-5-6/14764 "2024-10-24T17:51:17Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Manjunath\_AV](https://discourse.vtk.org/user_avatar/discourse.vtk.org/manjunath_av/32/9403_2.png) [@Manjunath\_AV](https://discourse.vtk.org/u/Manjunath_AV)
#### Post date: [October 24, 2024, 5:51pm UTC](https://discourse.vtk.org/t/qvtkopenglnativewidget-in-qgraphicsview-causing-white-screen-in-qt-6-5-6/14764/1 "2024-10-24T17:51:17Z")

</div>

We are currently in the process of porting our project from Qt 5.15 to Qt 6.5.6. In Qt 5.15, we were successfully using QGLWidget in conjunction with QGraphicsView. However, after the upgrade to Qt 6, we have replaced QGLWidget with QOpenGLWidget due to the deprecation of QGLWidget. Unfortunately, this change has caused an issue when setting the viewport for QGraphicsView using setViewport().

The issue we are facing is that when we call setViewport() with QOpenGLWidget, it results in a white screen, and we are unable to see the 3D image in QVTKOPENGLNATIVEWIDGET. However, if we comment out the setViewport() line, the rest of the functionality works fine, but this is not an option as setViewport() is required for further processing in our application.

Additionally, we have tried enabling Qt::AA\_ShareOpenGLContexts and setting a shared OpenGL context, but neither approach resolved the issue. Here is the relevant part of the code:

QGraphicsScene\* scene = new QGraphicsScene();  
graphicsView-\>setScene(scene);

QSurfaceFormat fmt;  
fmt.setSwapInterval(0); // Turn off vSync.  
fmt.setSwapBehavior(QSurfaceFormat::DoubleBuffer);

QOpenGLWidget\* openGLWidget = new QOpenGLWidget();  
openGLWidget-\>setFormat(fmt);

// Commenting setViewport works fine, but setViewport causes a white screen  
// graphicsView-\>setViewport(openGLWidget);  
graphicsView-\>resize(800, 600);

// Graphics widget contains OpenGLWidget which loads a 3D image, graphics widget has QVTKOPENGLNATIVEWIDGET  
scene-\>addItem(view-\>graphicsWidget());

graphicsView-\>setFrameStyle(QFrame::NoFrame);  
graphicsView-\>setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);  
graphicsView-\>setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);  
graphicsView-\>setViewportUpdateMode(QGraphicsView::FullViewportUpdate);  
graphicsView-\>setOptimizationFlag(QGraphicsView::DontSavePainterState);

graphicsView-\>show();

Could you please review this issue and provide guidance on how to resolve it? Any suggestions on getting the QOpenGLWidget to work properly with setViewport() would be greatly appreciated.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [March 3, 2025, 9:26pm UTC](https://discourse.vtk.org/t/qvtkopenglnativewidget-in-qgraphicsview-causing-white-screen-in-qt-6-5-6/14764/2 "2025-03-03T21:26:50Z")

</div>

Cc: @sankhesh
