def labelTextWidth(label):
    """ Returns the width of label text of the label in pixels.

        IMPORTANT: does not work when the labels are styled using style sheets.

        Unfortunately it is possible to retrieve the settings (e.g. padding) that were set by the
        style sheet without parsing the style sheet as text.
    """
    fontMetrics = label.fontMetrics()
    contentsWidth = fontMetrics.size(label.alignment(), label.text()).width()
    if label.indent() < 0 and label.frameWidth():
        indent = fontMetrics.width('x') / 2 - label.margin()
        indent *= 2
    else:
        indent = label.indent()
    result = contentsWidth + indent + 2 * label.frameWidth(
        ) + 2 * label.margin()
    if 1:
        print('contentsWidth: {}'.format(contentsWidth))
        print('lineWidth: {}'.format(label.lineWidth()))
        print('midLineWidth: {}'.format(label.midLineWidth()))
        print('frameWidth: {}'.format(label.frameWidth()))
        print('margin: {}'.format(label.margin()))
        print('indent: {}'.format(label.indent()))
        print('actual indent: {}'.format(indent))
        print('RESULT: {}'.format(result))
        print()
    return result
