Desktop rendering issue with QGridLayout, Windows, Nvidia, PySide6
-
I am stuck trying to troubleshoot a rendering issue where the QMainWindow background peeks through the central widget and its QGridLayout. The background should be solid black, but sometimes I see the red of the QMainWindow background like this:
The rendering issue only occurs if the QLabels are updated and the window resizes. Here is a GIF in action:
The platform is:
- Windows 11 x64
- Python x64 3.9.10
- PySide 6.2.3 with Qt6
- Renderer: NVIDIA GeForce RTX 2060/PCIe/SSE2
- Version: 4.6.0 NVIDIA 511.79
- Dual displays: 2194x1234+0+0 (native: 3840x2160+0+0) Available: 2194x1186+0+0
If I disable the QLabel updates using the "--noupdate" option in the script below, then this rendering issue does not occur, and the background remains solid black during window resizes.
I am posting here rather than the python group since this appears to be a Qt-related issue, not a python binding issue.
I appreciate any tips on what to investigate!
Here is the minimal example:
""" Demonstrate PySide6 drawing artifacts pip install -U PySide6 """ from PySide6 import QtCore, QtGui, QtWidgets import argparse import sys import time INSTRUCTIONS = """\ Drag the bottom corner of the Window to resize it. At some dimensions, red lines appear that remain. The red comes from the main window's background-color which should never peek through the central widget. If you provide the --noupdate argument, then the QLabels never update, and this error does not occur. """ TIMER_MS = 100 MAIN_WINDOW_STYLE = """\ QMainWindow { color: #00FF00; background-color: #FF0000; }""" CENTRAL_STYLE = """\ QWidget { padding: 0px; color: #000000; background-color: #000000; border-width: 1px; }""" LABEL_STYLE = """\ QLabel { padding: 0px; color: #FFFFFF; background-color: #000000; padding-left: 5px; padding-right: 5px; padding-top: 5px; padding-bottom: 5px; border-width: 0px; }""" class MainWindow(QtWidgets.QMainWindow): def __init__(self, noupdate=False): super(MainWindow, self).__init__() self.setStyleSheet(MAIN_WINDOW_STYLE) self.central_widget = QtWidgets.QWidget(self) self.central_widget.setStyleSheet(CENTRAL_STYLE) self.setCentralWidget(self.central_widget) layout = QtWidgets.QGridLayout(self.central_widget) self._layout = layout layout.setContentsMargins(0, 0, 0, 0) layout.setHorizontalSpacing(0) layout.setVerticalSpacing(0) self._widgets = [] widgets = self._widgets for row in range(4): for col in range(3): w = QtWidgets.QLabel("hi", self.central_widget) w.setStyleSheet(LABEL_STYLE) layout.addWidget(w, row * 4, col, 4, 1) widgets.append(w) for idx in range(4): w = QtWidgets.QLabel("hi", self.central_widget) w.setStyleSheet(LABEL_STYLE) layout.addWidget(w, row * 4 + idx, 3, 1, 1) widgets.append(w) self._timer = QtCore.QTimer() self._timer.setSingleShot(True) self._timer.timeout.connect(self._on_timer) if not noupdate: self._timer.start(TIMER_MS) @QtCore.Slot() def _on_timer(self): t = int(time.time() * 100) for idx, w in enumerate(self._widgets): w.setText(str(t + idx)) self._timer.start(TIMER_MS) def _parse_args(): parser = argparse.ArgumentParser(description='Demostrate PySide6 rendering issue.') parser.add_argument('--noupdate', action='store_true', help='Disable QLabel updates.') return parser.parse_args() if __name__ == '__main__': args = _parse_args() print(INSTRUCTIONS) #QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseDesktopOpenGL) app = QtWidgets.QApplication() ui = MainWindow(noupdate=args.noupdate) ui.show() app.exec()
And here is the qtdiag output:
Qt 6.2.3 (x86_64-little_endian-llp64 shared (dynamic) release build; by MSVC 2019) on "windows" OS: Windows 11 Version 2009 [winnt version 10.0.22000] Architecture: x86_64; features: SSE2 SSE3 SSSE3 SSE4.1 SSE4.2 AVX AVX2 Environment: Features: QT_NO_EXCEPTIONS Library info: PrefixPath: C:\bin\Python3_9_10\Lib\site-packages\PySide6 DocumentationPath: C:\bin\Python3_9_10\Lib\site-packages\PySide6\doc HeadersPath: C:\bin\Python3_9_10\Lib\site-packages\PySide6\include LibrariesPath: C:\bin\Python3_9_10\Lib\site-packages\PySide6\lib LibraryExecutablesPath: C:\bin\Python3_9_10\Lib\site-packages\PySide6\bin BinariesPath: C:\bin\Python3_9_10\Lib\site-packages\PySide6\bin PluginsPath: C:\bin\Python3_9_10\Lib\site-packages\PySide6\plugins QmlImportsPath: C:\bin\Python3_9_10\Lib\site-packages\PySide6\qml ArchDataPath: C:\bin\Python3_9_10\Lib\site-packages\PySide6 DataPath: C:\bin\Python3_9_10\Lib\site-packages\PySide6 TranslationsPath: C:\bin\Python3_9_10\Lib\site-packages\PySide6\translations ExamplesPath: C:\bin\Python3_9_10\Lib\site-packages\PySide6\examples TestsPath: C:\bin\Python3_9_10\Lib\site-packages\PySide6\tests SettingsPath: Standard paths [*...* denote writable entry]: DesktopLocation: "Desktop" *C:\Users\Matth\Desktop* DocumentsLocation: "Documents" *C:\Users\Matth\Documents* FontsLocation: "Fonts" *C:\WINDOWS\Fonts* ApplicationsLocation: "Applications" *C:\Users\Matth\AppData\Roaming\Microsoft\Windows\Start Menu\Programs* MusicLocation: "Music" *C:\Users\Matth\Music* MoviesLocation: "Movies" *C:\Users\Matth\Videos* PicturesLocation: "Pictures" *C:\Users\Matth\Pictures* TempLocation: "Temporary Directory" *C:\Users\Matth\AppData\Local\Temp* HomeLocation: "Home" *C:\Users\Matth* AppLocalDataLocation: "Application Data" *C:\Users\Matth\AppData\Local\QtProject\qtdiag* C:\ProgramData\QtProject\qtdiag C:\bin\Python3_9_10\Lib\site-packages\PySide6 C:\bin\Python3_9_10\Lib\site-packages\PySide6\data C:\bin\Python3_9_10\Lib\site-packages\PySide6\data\QtProject\qtdiag CacheLocation: "Cache" *C:\Users\Matth\AppData\Local\QtProject\qtdiag\cache* GenericDataLocation: "Shared Data" *C:\Users\Matth\AppData\Local* C:\ProgramData C:\bin\Python3_9_10\Lib\site-packages\PySide6 C:\bin\Python3_9_10\Lib\site-packages\PySide6\data RuntimeLocation: "Runtime" *C:\Users\Matth* ConfigLocation: "Configuration" *C:\Users\Matth\AppData\Local\QtProject\qtdiag* C:\ProgramData\QtProject\qtdiag C:\bin\Python3_9_10\Lib\site-packages\PySide6 C:\bin\Python3_9_10\Lib\site-packages\PySide6\data C:\bin\Python3_9_10\Lib\site-packages\PySide6\data\QtProject\qtdiag DownloadLocation: "Download" *C:\Users\Matth\Downloads* GenericCacheLocation: "Shared Cache" *C:\Users\Matth\AppData\Local\cache* GenericConfigLocation: "Shared Configuration" *C:\Users\Matth\AppData\Local* C:\ProgramData C:\bin\Python3_9_10\Lib\site-packages\PySide6 C:\bin\Python3_9_10\Lib\site-packages\PySide6\data AppDataLocation: "Application Configuration" *C:\Users\Matth\AppData\Roaming\QtProject\qtdiag* C:\ProgramData\QtProject\qtdiag C:\bin\Python3_9_10\Lib\site-packages\PySide6 C:\bin\Python3_9_10\Lib\site-packages\PySide6\data C:\bin\Python3_9_10\Lib\site-packages\PySide6\data\QtProject\qtdiag AppConfigLocation: "Application Configuration" *C:\Users\Matth\AppData\Local\QtProject\qtdiag* C:\ProgramData\QtProject\qtdiag C:\bin\Python3_9_10\Lib\site-packages\PySide6 C:\bin\Python3_9_10\Lib\site-packages\PySide6\data C:\bin\Python3_9_10\Lib\site-packages\PySide6\data\QtProject\qtdiag File selectors (increasing order of precedence): en_US windows winnt Network: Using "Secure Channel, Windows 10.0.22000", version: 0xa0055f0 Platform capabilities: ThreadedPixmaps OpenGL ThreadedOpenGL WindowMasks MultipleWindows ForeignWindows NonFullScreenWindows NativeWidgets WindowManagement RasterGLSurface AllGLFunctionsQueryable Style hints: mouseDoubleClickInterval: 550 mousePressAndHoldInterval: 800 startDragDistance: 10 startDragTime: 500 startDragVelocity: 0 keyboardInputInterval: 400 keyboardAutoRepeatRate: 32 cursorFlashTime: 1060 showIsFullScreen: 0 showIsMaximized: 0 passwordMaskDelay: 0 passwordMaskCharacter: U+25CF fontSmoothingGamma: 1.2 useRtlExtensions: 0 setFocusOnTouchRelease: 0 tabFocusBehavior: Qt::TabFocusAllControls singleClickActivation: 0 Additional style hints (QPlatformIntegration): ReplayMousePressOutsidePopup: 1 Theme: Platforms requested : windows available : Styles requested : WindowsVista,Windows available : windowsvista,Windows,Fusion System font : "Segoe UI" 9 Native file dialog Fonts: General font : "Segoe UI" 9 Fixed font : "Courier New" 9 Title font : "Segoe UI" 9 Smallest font: "Segoe UI" 9 Palette: QPalette::WindowText: #ff000000 QPalette::Button: #fff0f0f0 QPalette::Light: #ffffffff QPalette::Midlight: #ffe3e3e3 QPalette::Dark: #ffa0a0a0 QPalette::Mid: #ffa0a0a0 QPalette::Text: #ff000000 QPalette::BrightText: #ffffffff QPalette::ButtonText: #ff000000 QPalette::Base: #ffffffff QPalette::Window: #fff0f0f0 QPalette::Shadow: #ff696969 QPalette::Highlight: #ff0078d7 QPalette::HighlightedText: #ffffffff QPalette::Link: #ff0000ff QPalette::LinkVisited: #ffff00ff QPalette::AlternateBase: #ffe9e7e3 QPalette::NoRole: #ff000000 QPalette::ToolTipBase: #ffffffdc QPalette::ToolTipText: #ff000000 QPalette::PlaceholderText: #80000000 Screens: 2, High DPI scaling: active # 0 "\\.\DISPLAY1" Depth: 32 Primary: yes Manufacturer: Model: Serial number: Geometry: 2194x1234+0+0 (native: 3840x2160+0+0) Available: 2194x1186+0+0 Virtual geometry: 6034x1234-3840+0 Available: 6034x1186-3840+0 2 virtual siblings Physical size: 597x336 mm Refresh: 59.997 Hz Power state: 0 Physical DPI: 93.3461,93.2845 Logical DPI: 96,96 (native: 168,168) Subpixel_None High DPI scaling factor: 1.75 DevicePixelRatio: 1.75 Primary orientation: 2 Orientation: 2 Native orientation: 0 # 1 "\\.\DISPLAY5" Depth: 32 Primary: no Manufacturer: Model: Serial number: Geometry: 2194x1234-3840+0 (native: 3840x2160-3840+0) Available: 2194x1186-3840+0 Virtual geometry: 6034x1234-3840+0 Available: 6034x1186-3840+0 2 virtual siblings Physical size: 597x336 mm Refresh: 59.9367 Hz Power state: 0 Physical DPI: 93.3461,93.2845 Logical DPI: 96,96 (native: 168,168) Subpixel_None High DPI scaling factor: 1.75 DevicePixelRatio: 1.75 Primary orientation: 2 Orientation: 2 Native orientation: 0 Dynamic GL LibGL Vendor: NVIDIA Corporation Renderer: NVIDIA GeForce RTX 2060/PCIe/SSE2 Version: 4.6.0 NVIDIA 511.79 Shading language: 4.60 NVIDIA Format: Version: 4.6 Profile: 2 Swap behavior: 2 Buffer size (RGBA): 8,8,8,8 Depth buffer: 24 Stencil buffer: 8 Profile: None (QOpenGLFunctions_4_6) Vulkan instance available Supported instance extensions: VK_KHR_surface, version 25 VK_KHR_win32_surface, version 5 VK_KHR_external_memory_capabilities, version 1 VK_KHR_external_semaphore_capabilities, version 1 VK_KHR_external_fence_capabilities, version 1 VK_KHR_get_physical_device_properties2, version 2 VK_KHR_get_surface_capabilities2, version 1 VK_KHR_device_group_creation, version 1 VK_EXT_swapchain_colorspace, version 3 VK_KHR_display, version 23 VK_KHR_get_display_properties2, version 1 VK_KHR_surface_protected_capabilities, version 1 VK_EXT_debug_report, version 10 VK_EXT_debug_utils, version 2 VK_EXT_direct_mode_display, version 1 VK_NV_external_memory_capabilities, version 1 Supported layers: VK_LAYER_NV_optimus, version 1, spec version 1.3.194, NVIDIA Optimus layer VK_LAYER_OBS_HOOK, version 1, spec version 1.2.131, Open Broadcaster Software hook VK_LAYER_VALVE_steam_overlay, version 1, spec version 1.2.136, Steam Overlay Layer VK_LAYER_VALVE_steam_fossilize, version 1, spec version 1.2.136, Steam Pipeline Caching Layer Available physical devices: API version 1.3.194, vendor 0x10DE, device 0x1F08, NVIDIA GeForce RTX 2060, type 2, driver version 511.316.0 API version 1.2.177, vendor 0x8086, device 0x3E98, Intel(R) UHD Graphics 630, type 1, driver version 0.402.1472 GPU #1: Card name : NVIDIA GeForce RTX 2060 Driver Name : nvldumdx.dll Driver Version : 30.0.15.1179 Vendor ID : 0x10DE Device ID : 0x1F08 SubSys ID : 0x37591028 Revision ID : 0x00A1 GPU #2: Card name : Intel(R) UHD Graphics 630 Driver Name : igdumdim64.dll Driver Version : 27.20.100.9664 Vendor ID : 0x8086 Device ID : 0x3E98 SubSys ID : 0x08591028 Revision ID : 0x0002 Qt Rendering Hardware Interface supported backends: OpenGL (with default QSurfaceFormat): Driver Info: Device: NVIDIA Corporation NVIDIA GeForce RTX 2060/PCIe/SSE2 4.6.0 NVIDIA 511.79 Device ID: 0x0 Vendor ID: 0x0 Device type: Unknown Min Texture Size: 1 Max Texture Size: 32768 Max Color Attachments: 8 Frames in Flight: 1 Async Readback Limit: 1 MaxThreadGroupsPerDimension: 65535 MaxThreadsPerThreadGroup: 1024 MaxThreadGroupX: 1024 MaxThreadGroupY: 1024 MaxThreadGroupZ: 64 Uniform Buffer Alignment: 1 Supported MSAA sample counts: 1,2,4,8,16,32 Features: v MultisampleTexture v MultisampleRenderBuffer - DebugMarkers - Timestamps v Instancing - CustomInstanceStepRate v PrimitiveRestart v NonDynamicUniformBuffers v NonFourAlignedEffectiveIndexBufferOffset v NPOTTextureRepeat - RedOrAlpha8IsRed v ElementIndexUint v Compute v WideLines v VertexShaderPointSize v BaseVertex - BaseInstance v TriangleFanTopology v ReadBackNonUniformBuffer v ReadBackNonBaseMipLevel v TexelFetch v RenderToNonBaseMipLevel v IntAttributes v ScreenSpaceDerivatives - ReadBackAnyTextureFormat Texture formats: RGBA8 BGRA8 R8 R16 RG8 RED_OR_ALPHA8 RGBA16F RGBA32F R16F R32F D16 D32F BC1 BC2 BC3 ETC2_RGB8 ETC2_RGB8A1 ETC2_RGBA8 ASTC_4x4 ASTC_5x4 ASTC_5x5 ASTC_6x5 ASTC_6x6 ASTC_8x5 ASTC_8x6 ASTC_8x8 ASTC_10x5 ASTC_10x6 ASTC_10x8 ASTC_10x10 ASTC_12x10 ASTC_12x12 Vulkan: Driver Info: Device: NVIDIA GeForce RTX 2060 Device ID: 0x1F08 Vendor ID: 0x10DE Device type: Discrete Min Texture Size: 1 Max Texture Size: 32768 Max Color Attachments: 8 Frames in Flight: 2 Async Readback Limit: 2 MaxThreadGroupsPerDimension: 65535 MaxThreadsPerThreadGroup: 1024 MaxThreadGroupX: 1024 MaxThreadGroupY: 1024 MaxThreadGroupZ: 64 Uniform Buffer Alignment: 64 Supported MSAA sample counts: 1,2,4,8 Features: v MultisampleTexture v MultisampleRenderBuffer - DebugMarkers v Timestamps v Instancing - CustomInstanceStepRate v PrimitiveRestart v NonDynamicUniformBuffers v NonFourAlignedEffectiveIndexBufferOffset v NPOTTextureRepeat v RedOrAlpha8IsRed v ElementIndexUint v Compute v WideLines v VertexShaderPointSize v BaseVertex v BaseInstance v TriangleFanTopology v ReadBackNonUniformBuffer v ReadBackNonBaseMipLevel v TexelFetch v RenderToNonBaseMipLevel v IntAttributes v ScreenSpaceDerivatives v ReadBackAnyTextureFormat Texture formats: RGBA8 BGRA8 R8 R16 RG8 RED_OR_ALPHA8 RGBA16F RGBA32F R16F R32F D16 D32F BC1 BC2 BC3 BC4 BC5 BC6H BC7 Direct3D 11: Driver Info: Device: NVIDIA GeForce RTX 2060 Device ID: 0x1F08 Vendor ID: 0x10DE Device type: Unknown Min Texture Size: 1 Max Texture Size: 16384 Max Color Attachments: 8 Frames in Flight: 1 Async Readback Limit: 1 MaxThreadGroupsPerDimension: 65535 MaxThreadsPerThreadGroup: 1024 MaxThreadGroupX: 1024 MaxThreadGroupY: 1024 MaxThreadGroupZ: 64 Uniform Buffer Alignment: 256 Supported MSAA sample counts: 1,2,4,8 Features: v MultisampleTexture v MultisampleRenderBuffer v DebugMarkers v Timestamps v Instancing v CustomInstanceStepRate v PrimitiveRestart - NonDynamicUniformBuffers v NonFourAlignedEffectiveIndexBufferOffset v NPOTTextureRepeat v RedOrAlpha8IsRed v ElementIndexUint v Compute - WideLines - VertexShaderPointSize v BaseVertex v BaseInstance - TriangleFanTopology v ReadBackNonUniformBuffer v ReadBackNonBaseMipLevel v TexelFetch v RenderToNonBaseMipLevel v IntAttributes v ScreenSpaceDerivatives v ReadBackAnyTextureFormat Texture formats: RGBA8 BGRA8 R8 R16 RG8 RED_OR_ALPHA8 RGBA16F RGBA32F R16F R32F D16 D32F BC1 BC2 BC3 BC4 BC5 BC6H BC7
-
I tried the example on two other machines. One has the same behavior, the other works fine without any rendering artifacts.
The other bad computer is a laptop with a 1920x1080 display and an Nvidia graphics card.
The good computer is a desktop with a 1920x1080 display and just Intel graphics.
-
Hi and welcome to devnet,
Are you using the same NVIDIA driver version on both machines ?
If so, is it the latest ? If not, can you update ? If so, can you downgrade ?
-
Yes, both machines with Nvidia graphics cards are running the latest and greatest Nvidia driver 511.79 released 2/14/2022. That also matches the version reported in qtdiag:
Version: 4.6.0 NVIDIA 511.79
Using Windows device manager, I disabled my Nvidia graphics card, which should force it to use the built-in Intel UHD Graphics 630. I still see the same rendering issues. I will try to reboot and also then reinstall and older Nvidia driver, say from a year ago.
-
Rebooting to cleanly use the Intel graphics had no effect. The rendering issues were still the same.
I then re-enabled my nvidia card using Device Manager, and then downgraded to 471.41 from 2021.7.9. It appears to be the oldest driver that supports Win 11. Same rendering issue.
So, while there is certainly some computer-to-computer variability, it seems pretty repeatable on 2 out of my 3 computers.
@SGaist - anything else that you would recommend? I know that my example is python, but does it look right to you? Am I missing any Qt calls? Note that storing the widgets to a member is the Python-way of ensuring they aren't garbage collected...
-
Nothing stands out as wrong in your code.
I am wondering whether it's related to the 0px borders that you are using.
-
Interesting thought. I updated padding, padding-*, border-width, setContentsMargins, setHoriztonalSpacing, and setVerticalSpacing to all be 1 rather than zero. Same problem :(
I then completely removed all the padding, padding-*, border-width QSS specs, along with the calls to setContentsMargins, setHoriztonalSpacing, and setVerticalSpacing. Same problem :(
I have just asked Selmen d on Upwork to investigate this issue. Thanks for your help @SGaist, and I don't want to take more of your time. I will follow up here with whatever Selmen finds!
-
After further investigation, we believe that this is an issue with Qt's pixel rendering on Windows. We submitted a bug:
https://bugreports.qt.io/browse/QTBUG-101047 -
Thanks for the detailed analysis !