PySide2 Qt.TextAlignmentRole bug

Heads up! You've already completed this tutorial.

luis | 2020-09-30 16:19:14 UTC | #1

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: https://bugreports.qt.io/browse/PYSIDE-20

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


martin | 2020-09-30 16:22:47 UTC | #2

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.


Over 10,000 developers have bought Create GUI Applications with Python & Qt!
Create GUI Applications with Python & Qt6
Take a look

Downloadable ebook (PDF, ePub) & Complete Source code

Also available from Payhip , Gumroad , Leanpub and Amazon Paperback

[[ discount.discount_pc ]]% OFF for the next [[ discount.duration ]] [[discount.description ]] with the code [[ discount.coupon_code ]]

Purchasing Power Parity

Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]
Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak

PySide2 Qt.TextAlignmentRole bug was written by Martin Fitzpatrick .

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt.