About PyQt6 and PySide6

Heads up! You've already completed this tutorial.

PedanticHacker wrote

This is a question for Martin Fitzpatrick specifically. Will there ever be a book about PyQt6 and/or PySide6? I want to port my code to version 6, but I have a lot of issues. So I am wondering whether there are any plans in the air. Even just a porting guide from PyQt5/PySide2 to PyQt6/PySide6 would be a wonderful thing.

Martin Fitzpatrick

Short answer: yes! I've started work on it this week, just converting over the source code for the examples + familiarising myself with the changes (some things have been removed, e.g. QResources from PyQt6 so those sections will need to be rewritten).

It's early days, but I'll get porting guide out first + there is another update to the PyQt5 book on the way.

Martin Fitzpatrick

Getting there, about 90% of the code is migrated for both PyQt6 & PySide6. Then I have a list of changes to make to the book/conditional sections for the new libraries + we're good to go for a initial release. The v6 versions will be available to anyone who's bought an earlier edition.

All the code for the different versions is auto-generated from the PyQt5 source. PyQt5 to PySide2 requires replacing the imports and signal/slot names + some manual handwritten replacements for the UI loader. The same process has been done for v6 and that's given me some insight into where the incompatibilities are.

Some first thoughts from the migration --

  • PyQt6 is less directly source-compatible with PyQt6 than PySide6. In PyQt6 the namespaces have been moved under Python Enums so e.g. Qt.DisplayRole is now under Qt.ItemDataRole.DisplayRole. The same structure exists now in PySide6, but the old locations are retained, so it's backwards compatible Qt.ItemDataRole.BackgroundRole == Qt.BackgroundRole. I'm 50/50 on whether to use the new style in the PySide6 book -- thoughts?
  • (PyQt6 & PySIde6) QAction is now in QtGui not QtWidgets. This always caught me out (since it's not a widget) so I think it's a good change. But it's hard to auto-migrate.
  • (PyQt6 & PySIde6) Retrieving a pixmap now seems to return a copy: if you get a labels pixmap and draw on it, it doesn't affect the widget. Required a rewrite of the custom widget code. May be missing something here, early days.
  • (PyQt6) QMouseEvent now doesn't have .x() or .y() which is odd. You need to get a position via QMouseEvent.position() instead.

The matplotlib examples won't work until Qt6 is supported there and there is (as yet) no support for packaging PyQt6/PySide6 in PyInstaller or fbs. I'll remove this part of the book until it becomes available.

Should be out, at least in an "early access" form, by next week.

IMG_20210305_172632689|666x500, 75%


The same structure exists now in PySide6, but the old locations are retained, so it’s backwards compatible Qt.ItemDataRole.BackgroundRole == Qt.BackgroundRole. I’m 50/50 on whether to use the new style in the PySide6 book – thoughts?

I think it'd be best to use the new style, because someday in the future that backwards compatibility might be removed. Just my 2 cents.

Martin Fitzpatrick

Yesterday I noticed that while PyQt6 & PySide2 Enum types are identical between PyQt6 & PySide6, flag types have different names. So Qt.GlobalColor.white (enum) is the same in both. But alignment flags are in Qt.Alignment.AlignLeft in PyQt6 and Qt.AlignmentFlag.AlignLeft in PySide6.


The PySide6 edition is now available -- check your "Books & Downloads" to get the free update. I'm working on the PyQt6 edition and this should be out next week.

For this update I've kept PySide6 using the short-form names, since this matches what is used in the PySide6 documentation. Will keep an eye on how things change in future, it's a bit painful to maintain the two different styles.

Andrew Rusanovsky

In PySide6.1, the functions:

  • all are deprecated.


The matplotlib examples won’t work until Qt6 is supported there

The experimental branch with Qt6 support which is mentioned in the book, ch. 36 Plotting with Matplotlib, PDF p. 582, has recently been merged into Matplotlib's master branch. This should be in Matplotlib v3.5, apparently due tomorrow August 18, and then soon after in PyPI, so the experimental branch will no longer be needed.

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

About PyQt6 and PySide6 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.