I don't think that is possible since in a lot of windowing systems drawing of window decorations is not in control of the application and the windowing system's decoration handler does not provide the feedback to react to this.

You might be able to do this in a platform specific way, e.g. using some native API to query which font is used for window titles and then use QFontMetrics to calculate the size of your title text.

Cheers,
_