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

Baptiste Lepilleur blep at users.sourceforge.net
Sat Jun 30 12:12:44 BST 2007


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)

Baptiste.



More information about the PyQt mailing list