Clone
10
Plugin migration to be compatible with Qt5 and Qt6
Matthias Kuhn edited this page 2025-02-11 08:02:09 +01:00

Qt6 migration

It's possible to make a plugin for both Qt5 and Qt6.

Script

  1. pip install astpretty tokenize-rt
  2. Install python3-pyqt6, python3-pyqt6.qtsvg, python3-pyqt6.qsci
  3. Download the pyqt5_to_pyqt6 script
  4. You should check that PyQt5 is not available in the Python environment, the script will work better
  5. pyqt5_to_pyqt6.py /path/to/plugin
  6. Edit the metadata.txt by adding supportsQt6=True

This will get you in the right direction but might not do all necessary changes. Make sure to test your plugin thoroughly. Consider using an IDE with inspection that can notify you about broken imports, bad usage or non-existent references.

Official C++ documentation

Manual conversion

To make a code working for both versions, it's mostly about how enums are called. For instance, according to Qt Namespace :

Working only in PyQt5 Working for both PyQt5 and PyQt6
Qt.UserRole Qt.ItemDataRole.UserRole
Qt.WaitCursor Qt.CursorShape.WaitCursor
Qt.blue Qt.GlobalColor.blue
etc. etc.