Porting Applications from PySide2 to PySide6¶
Module Availability¶
Qt for Python 6.2.0 provides all modules planned for inclusion in Qt 6.
Module-Level Changes¶
The modules QtMacExtras, Qt Quick Controls 1, QtWinExtras, QtXmlPatterns and QtX11Extras have been removed.
QStateMachineand related classes have been extracted to a new QtStateMachine module.The modules QtWebKit and QtWebKitWidgets have been replaced by the new QtWebEngineCore, QtWebEngineQuick and QtWebEngineWidgets modules.
QXmlReaderand related classes (SAX API) have been removed.The content of the QtOpenGL module has been replaced. The class
QGLWidgetand related classes (QGLContext,QGLFunctions,QGLShaderProgram) have been removed. Parts of the Open GL functionality from QtGui have been extracted into this module, for exampleQOpenGLBufferandQOpenGLShaderProgram. There is a new module QtOpenGLWidgets which contains the classQOpenGLWidget, a replacement forQGLWidget.
As Open GL is phasing out, QRhi should be considered for graphics applications.
Imports¶
The first thing to do when porting applications is to replace the import statements:
from PySide2.QtWidgets import QApplication
from PySide2 import QtCore
needs to be changed to:
from PySide6.QtWidgets import QApplication
from PySide6 import QtCore
Some classes are in a different module now, for example
QAction and QShortcut have been moved from QtWidgets to QtGui.
For Qt Charts and Qt Data Visualization, the additional namespaces have been removed. It is now possible to use:
from PySide6.QtCharts import QChartView
directly.
Class/Function Deprecations¶
Then, the code base needs to be checked for usage of deprecated API and adapted accordingly. For example:
The High DPI scaling attributes
Qt.AA_EnableHighDpiScaling,Qt.AA_DisableHighDpiScalingandQt.AA_UseHighDpiPixmapsare deprecated. High DPI is by default enabled in Qt 6 and cannot be turned off.QDesktopWidgethas been removed.QScreenshould be used instead, which can be retrieved usingQWidget.screen(),QGuiApplication.primaryScreen()orQGuiApplication.screens().QFontMetrics.width()has been renamed tohorizontalAdvance().QMouseEvent.pos()andQMouseEvent.globalPos()returning aQPointas well asQMouseEvent.x()andQMouseEvent.y()returningintare now deprecated.QMouseEvent.position()andQMouseEvent.globalPosition()returning aQPointFshould be used instead.Qt.MidButtonhas been renamed toQt.MiddleButton.QOpenGLVersionFunctionsFactory.get()instead ofQOpenGLContext.versionFunctions()should be used to obtain Open GL functions.QRegExphas been replaced byQRegularExpression.QWidget.mapToGlobal()andQWidget.mapFromGlobal()now also accept and returnQPointF.Functions named
exec_(classesQCoreApplication,QDialog,QEventLoop) have been renamed toexecwhich became possible in Python 3.
More information can be found in the Porting to Qt 6 Guide and the Qt 6.2 Documentation .