I feel this is related to How can I grab a window with widgets and title bar?, but maybe it has a different solution.
When capturing a (window with a) title bar, I get unexpected results after resizing.
from PySide6.QtWidgets import QApplication, QMainWindow, QStyle
application = QApplication()
title_bar_height = application.style().pixelMetric(QStyle.PixelMetric.PM_TitleBarHeight)
window = QMainWindow()
window.show()
screen = window.screen()
def grab_titlebar(width: int) -> None:
window.resize(width, title_bar_height)
window.screen().grabWindow(
window.winId(), x=0, y=-title_bar_height, w=window.width(), h=title_bar_height
).save(f"titlebar{width}.png")
grab_titlebar(400)
grab_titlebar(500)
grab_titlebar(300)
400 px:
500 px:
300 px:
How can I make sure the title bar is updated before the snapshot?