PySide2 Qt.TextAlignmentRole bug

I’m working with the PySide2 edition of the book and I’m not getting the correct alignments in tableview_format_3.py or tableview_format_4.py

It seems to be a PySide2 bug: [PYSIDE-20] text alignment lost from QAbstractItemModel.data overrides - Qt Bug Tracker

I had to change the code from
return Qt.AlignVCenter | Qt.AlignRight
to
return int(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)

edit: my current setup is: Win10, Python 3.8.6 and PySide2 5.15.0

1 Like

Hi @luis welcome to the forum!

Thanks for the heads up and the workaround – the handling of these flags is one of the few things really noticeably different between PyQt5 & PySide2 (the two versions of the books differ quite a bit in this chapter) so I’ll get a note about this in the next PySide2 update.

Even once it’s fixed, this workaround will still be fine, so don’t worry about using it in projects.

1 Like