def calc_text_width(widget, text):
    """Estimate the width that the given text would take within the widget."""
    return (widget.fontMetrics().width(text) +
            widget.fontMetrics().width('M') +
            widget.contentsMargins().left() +
            widget.contentsMargins().right())