Assuming you have the text that needs to be displayed as a string, see QFontMetrics to calculate the width needed to display it given the widget's current font.

Cheers,
_