[Interest] How to Sync Resize event between QWidget and Metal surface widget

sivan nanthiran nanthiran2005 at gmail.com
Wed Jun 8 02:54:42 CEST 2022


I have written a custom widget which supports Metal surface by inheriting
QWidget. Here are the flags that I have set for this widget in the

> setAttribute(Qt::WA_DontCreateNativeAncestors);
> windowHandle()->setSurfaceType(QWindow::MetalSurface);
> setAttribute(Qt::WA_PaintOnScreen);
> setAttribute(Qt::WA_OpaquePaintEvent);

All the rendering and performance is working fine. However, there is an
issue when this Metal widget is resized within a QSplitter widget. For
example, I have added this Metal widget and QWidget into a QSplitter widget
and when the splitter handle is used to resize those widgets, there seems
to be a flickering effect sometimes.

After doing a screen recording, I noticed that the Metal widget's size is
taking effect immediately while the QWidget's actual size is not updated on
the screen although the QWidget::size() returned is the correct value. See
the screenshot attached below:

The RED is a Metal widget, while the BLUE and GREEN are QWidgets. The RED
and GREEN widgets are parented by a QWidget which is then added into
QSplitter together with BLUE widget.

Screenshot A shows NO artifact. Screenshot B shows an empty gray area. This
screenshot was captured when I was collapsing the Metal widget portion. As
you can see, the actual size of the Metal (RED) widget's parent is not
updated although the text rendered on it shows the correct size. In this
case, the gray area is seen because Metal widget's size is updated on
screen before its parent widget size is updated.

So is there any way that I can synchronize this resize event so that the
empty space can be avoided? Anyway to schedule Metal widget's resize or to
know when the QWidget's size is actually updated on the screen?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20220608/6d840e47/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: A.jpeg
Type: image/jpeg
Size: 55394 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20220608/6d840e47/attachment-0002.jpeg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: B.jpeg
Type: image/jpeg
Size: 57001 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20220608/6d840e47/attachment-0003.jpeg>

More information about the Interest mailing list