@SimonSchroeder
I think I'm already doing what you're suggesting.
I've implemented a custom resizeEvent(...) that calls timer.start() on a single shot timer every time a ResizeEvent is recieved. This also resets the timer if an event is received shortly after another.
And then I perform the actual resize of the widget when the timer times out.
ChatGPT Suggested using this:
import sys
from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel
from PyQt6.QtCore import QTimer, QAbstractNativeEventFilter
from PyQt6.QtGui import QGuiApplication
class NativeResizeFilter(QAbstractNativeEventFilter):
"""Listens for native window events to detect when resizing stops."""
def __init__(self, callback):
super().__init__()
self.callback = callback # Function to call when resize stops
def nativeEventFilter(self, eventType, message):
from ctypes import windll
if eventType == "windows_generic_MSG":
msg = int.from_bytes(message[:8], byteorder=sys.byteorder)
WM_EXITSIZEMOVE = 0x0232 # Windows event when resizing stops
if msg == WM_EXITSIZEMOVE:
self.callback()
return False, 0
It seems (!) to be potentially possible to do the deferred scaling using events on Windows.
I've also looked into dealing with NativeEvents on MacOS and Linux however, it seems to be rather tedious.
So as for now, I've opted to go with the timer and maybe do the fancy resizing if I have the time to spare.
AliSot2000