PyQt5 QWebEngineView flashes when resizing parent QFrame, how to prevent it?

2 weeks ago 8
ARTICLE AD BOX

The flash happens because QWebEngineView runs Chromium in a separate process. When you resize the widget, Qt updates geometry instantly but Chromium needs a frame or two to catch up — that gap is the flash.

Quick Fix: Set the page background color

The white flash is Chromium's default background showing through. Kill it at the source:

self.web_widget.page().setBackgroundColor(Qt.transparent)

If it still flickers: Animate the resize

Jumping 150px in one frame is the worst case. Spread it out and Chromium keeps up:

from PyQt5.QtCore import QPropertyAnimation, QSize, QEasingCurve def toggle_size(self): target = QSize(150, 150) if self.is_big else QSize(300, 300) for prop in (b"minimumSize", b"maximumSize"): anim = QPropertyAnimation(self.box, prop, self) anim.setDuration(200) anim.setStartValue(self.box.size()) anim.setEndValue(target) anim.setEasingCurve(QEasingCurve.InOutCubic) anim.start(QPropertyAnimation.DeleteWhenStopped) self.is_big = not self.is_big

Nuclear option: Disable GPU compositing

If nothing else works, set this before creating QApplication:

import os os.environ["QTWEBENGINE_CHROMIUM_FLAGS"] = "--disable-gpu-compositing"

Trades some rendering performance for no flash. Usually overkill.

Read Entire Article