Share

Qt changes

Maya Qt6 migration

Maya has moved from Qt5 and PySide2 to Qt6 and PySide6.

Information about porting C++ source code from Qt5 to Qt6 is available at https://doc.qt.io/qt-6/portingguide.html.

Information about porting Python source code from Qt5 to Qt6 is available at https://doc.qt.io/qtforpython-6/gettingstarted/porting_from2.html.

The following changes are most relevant to users of the Maya devkit:

We encourage users who build Qt plug-ins to provide feedback about their experience with Qt6 on the special Qt6 section of the forums.

Qt High DPI is always on in Qt 6

Check your high dpi logic, and verify that your plug-ins look correct on both high dpi displays and on mixed scaling environments.

Back to top

The platform-specific functionality previously contained in Qt <platform>Extras has been moved to QNativeInterface

See the Qt documentation on native interfaces for more details

Back to top

PySide6 Qt enums are now true Python enums

PySide6 Qt enums have changed from being Shiboken enums to true Python enums. While these are compatible in general, there are some differences:

  • Python enums cannot inherit from each other.
  • Python enums do not allow undefined values.
  • Python enums must have at least one argument.
  • Python enums rarely inherit from int.

For information on migrating from the old to the new enums, see Doing a Smooth Transition from the Old Enums in the Qt documentation.

Back to top

The name of the PySide python module has changed from PySide2 to PySide6

When using PySide scripts with both Qt6 and Qt5 builds of Maya, a try...except block can be used to import the appropriate version of Qt.

try:
  from PySide6.QtCore import QObject, Qt
except ImportError:
  from PySide2.QtCore import QObject, Qt

Back to top

PySide tool names have changed from PySide2 to PySide6

Tools such as pyside2-uic and pyside2-rcc have changed name to pyside6-uic and pyside6-rcc.

Back to top

The mayaSharedGLWidget property has been replaced by mayaSharedQOpenGLContext

The mayaSharedGLWidget property has been removed and replaced with the mayaSharedQOpenGLContext property.

As with mayaSharedGLWidget, the purpose of mayaSharedQOpenGLContext is to grant access to the shared GL context.

mayaSharedGLWidget was a QWidget pointer to a QGLWidget with a shared context. The context was obtained from the widget.

mayaSharedQOpenGLContext is a QObject pointer to the Maya viewport's QOpenGLContext. This means that the context is obtained directly from mayaSharedQOpenGLContext rather than through the GL widget.

For example, in Python:

from PySide6.QtWidgets import QApplication
context = QApplication.instance().property("mayaSharedQOpenGLContext")
# context is type <class 'PySide6.QtGui.QOpenGLContext'>

And in C++:

#include <QApplication>
#include <QVariant>
#include <QOpenGLContext>
[...]
  QVariant ctxVariant = QApplication::instance()->property("mayaSharedQOpenGLContext");
  QOpenGLContext *context = ctxVariant.value<QOpenGLContext*>();

Back to top

MQtUtil::resourceGLContext() now returns QOpenGLContext

Because QGLContext is deprecated in Qt6, MQtUtil::resourceGLContext() now returns QOpenGLContext.

QGLContext *MQtUtil::resourceGLContext()

Back to top

Explicit wrapping of QObjects is no longer required

Explicit wrapping of QObjects is no longer required. A change in QVariant means that the most specific wrapper will always be used automatically.

For example, in this case:

app = QApplication.instance()
sharedGLContext = app.property("mayaSharedQOpenGLContext")

The returned property is a QOpenGLContext. It does not need to be manually cast or wrapped.

Back to top

Other changes

  • Qt on macOS now uses Frameworks.
  • QtRegEx has been replaced with QRegularExpression.
  • QAction, QActionGroup, QShortcut, and QFileSystemModel have been moved to QtGui.

Back to top

Use the QT_DISABLE_DEPRECATED_UP_TO = 0x050F00 preprocessor directive

The QT_DISABLE_DEPRECATED_UP_TO = 0x050F00 preprocessor directive prevents Qt5 code that uses deprecated Qt APIs that are not in Qt6 from compiling. This directive should be used even when using Qt5. See the Qt porting guide's section on disabling the use of deprecated C++ API for more information.

Back to top

Was this information helpful?