-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Plugin migration to be compatible with Qt5 and Qt6
It's possible to make a plugin for both Qt5 and Qt6.
To run this script, you need QGIS with Qt6.
-
Install Python dependencies:
pip install astpretty tokenize-rt
-
Install additionnal system dependencies. Typically on Debian based-images:
sudo apt install python3-pyqt6 python3-pyqt6.qtsvg python3-pyqt6.qsci
-
Download the pyqt5_to_pyqt6 script
-
You should check that
PyQt5
is not available in the Python environment, the script will work better -
pyqt5_to_pyqt6.py /path/to/plugin
-
Edit the
metadata.txt
by addingsupportsQt6=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.
A bundled image with QGIS based on Qt6, including Oracle client and PDAL and the migration script is available: https://gitlab.com/Oslandia/qgis/pyqgis-4-checker. It can be used like this:
docker run --rm -v "$(pwd):/home/pyqgisdev/" registry.gitlab.com/oslandia/qgis/pyqgis-4-checker/pyqgis-qt-checker:latest pyqt5_to_pyqt6.py --logfile /home/pyqgisdev/pyqt6_checker.log .
The Docker image can also be used in a CI context to ensure compatibility along the development life-cycle.
stages:
- 🐍 lint
variables:
PROJECT_FOLDER: "{plugin_folder_path_within_git_repository}"
lint:qt6:
stage: 🐍 lint
image: registry.gitlab.com/oslandia/qgis/pyqgis-4-checker/pyqgis-qt-checker:latest
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
changes:
- "$PROJECT_FOLDER/**/*.py"
- ".gitlab-ci.yml"
when: on_success
- when: never
script:
# just print the script help
# - pyqt5_to_pyqt6.py --help
# first, a dry run to get the log file
- pyqt5_to_pyqt6.py --dry_run --logfile pyqt6_checker.log $PROJECT_FOLDER/
# then running with edit enabled to
- pyqt5_to_pyqt6.py $PROJECT_FOLDER/
artifacts:
paths:
- pyqt6_checker.log
when: always
access: all
expire_in: 3 days
- Removed Modules in Qt 6.0
- Porting to Qt 6
- Changes to Qt Modules in Qt 6
- Qt Namespace, all enums in Qt
https://www.riverbankcomputing.com/static/Docs/PyQt6/pyqt5_differences.html "gives an overview of the differences between PyQt6 and PyQt5. This is not an exhaustive list and does not go into the detail of the differences between the Qt v6 and Qt v5 APIs."
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. |