[PyQt] QPainter.boundingRect & flags, mixing enum types issue...

Phil Thompson phil at riverbankcomputing.co.uk
Sat Jun 30 14:07:35 BST 2007


On Saturday 30 June 2007 12:12 pm, Baptiste Lepilleur wrote:
> I'm stumbled uppon the error below when attempting to use
> QPainter.boundingRect:
>
> flags = QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop | QtCore.Qt.TextSingleLine
> bound = painter.boundingRect( QtCore.QRectF(), flags, word.text )
>
> Traceback (most recent call last):
>   File "test.pyw", line 142, in paintEvent
>     flags = QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop |
> QtCore.Qt.TextSingleLine
> TypeError: unsupported operand type(s) for |: 'Alignment' and 'TextFlag'
>
> The error seems to indicate that I can not mix 'Alignment' and 'TextFlag'
> enums, but the doc clearly says that I can. Is this a bug? If so, where
> should it be reported ?
>
> As a work-around, I'm using:
> flags = int(QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop) |
> int(QtCore.Qt.TextSingleLine)

It's a feature not a bug. Your workaround is the correct one.

Phil


More information about the PyQt mailing list