Qt6 Migration

Painter version 10.1 moved from Qt5 to Qt6, which introduces breaking changes in Python plugins. The most notable change in the PySide module going from version 2 to 6.

Plugins created before version 10.1 of Painter will need to be updated to work in newer versions.

Pyside changes

Affected entity
Before
Now
  • Pyside module name changed, so the import process is now different.
from PySide2 import QtWidgets, QtGui
from PySide6 import QtWidgets, QtGui
  • QAction is now under another module.
QtWidgets.QAction
QtGui.QAction
  • QKeySequence operator changed from + (plus) to | (pipe) character.
QtCore.Qt.CTRL + QtCore.Qt.Key_P
QtCore.Qt.CTRL | QtCore.Qt.Key_P
  • exec_() function has been replaced by exec().
dialog.exec_()
dialog.exec()
  • setMargin is replaced by setContentsMargins.
setMargin(10)
setContentsMargins(10, 10, 10, 10)

Dynamic check between Qt5 and Qt6

Writing plugins that work over several versions of Painter will require to check which version of the PySide module is available. Here is a simple code snippet that show how to achieve this:

# Qt5 vs Qt6 check import
import substance_painter as sp
IsQt5 = sp.application.version_info() < (10,1,0)

if IsQt5 :
  from PySide2 import QtGui
  from PySide2 import QtCore
  from PySide2 import QtWidgets
else :
  from PySide6 import QtGui
  from PySide6 import QtCore
  from PySide6 import QtWidgets

# Usage example
ActionBuilder = None
if IsQt5 :
  ActionBuilder = QtWidgets.QAction
else :
  ActionBuilder = QtGui.QAction

Action = ActionBuilder(
  "My menu action",
  triggered=MyFunctionToCall
)

Further information and guides

More information can be found on the Qt website:

recommendation-more-help
substance-3d-dev-help-painter-python-guide