How does one keeps plugin supported for Krita 5 and 6? Advice needed

Since Krita moving towards version 6.0 I expect that 5.0 will be around for a while. At least from the users perspective.

For plugin the import of PyQt5 will fail on Krita 6.0.

Is there a best practice to maintain the code for both Qt versions except from

try:
  import PyQt5
except ImportError:
  import PyQt6
1 Like

One alternative is to use Qt.py, it wraps PySide6, PyQt6, PySide2, PyQt5 under one interface. Qt.py is a single file so it is easy to add to existing package, and then all imports must be replaced to use it. Note that it uses PySide6 names instead of PyQt5.

example:

from Qt.QtCore import (
        Qt,
        QObject,
        Slot,      # note: not pyqtSlot !
        Signal,    # note: not pyqtSignal !
        Property)  # note: not pyqtProperty !

from Qt.QtGui import (
        QColor,
        QPalette)

from Qt.QtWidgets import (
        QApplication,
        QWidget)

edit: typo, uses PySide2 names → uses PySide6 names

/AkiR

4 Likes

What I used was

import krita
try:
    if int(krita.qVersion().split('.')[0]) == 5:
        raise
    from PyQt6.QtCore import *
    from PyQt6.QtGui import *
except:
    from PyQt5.QtCore import *
    from PyQt5.QtGui import *

Import error isn’t good enough sometimes if you have both Qt5 and Qt6 on a system since Qt5 will import fine without erroring.

1 Like

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.