From b938c9de19bf88fc3d966f78889080adc0046930 Mon Sep 17 00:00:00 2001 From: dalthviz <16781833+dalthviz@users.noreply.github.com> Date: Fri, 13 Dec 2024 18:02:06 -0500 Subject: [PATCH] Readd 'QAction' to QtWidgets with Qt version validation --- qtpy/QtWidgets.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/qtpy/QtWidgets.py b/qtpy/QtWidgets.py index f25c74f2..5f8c251a 100644 --- a/qtpy/QtWidgets.py +++ b/qtpy/QtWidgets.py @@ -37,11 +37,20 @@ def __getattr__(name): elif PYQT6: from PyQt6 import QtWidgets from PyQt6.QtGui import ( + QAction, QActionGroup, QFileSystemModel, QShortcut, QUndoCommand, ) + + if parse(_qt_version) < parse("6.4"): + # Make `QAction.setShortcut` and `QAction.setShortcuts` compatible with Qt>=6.4 + # See spyder-ide/qtpy#461 + from qtpy.QtGui import QAction + else: + from PyQt6.QtGui import QAction + from PyQt6.QtWidgets import * # Attempt to import QOpenGLWidget, but if that fails, @@ -110,9 +119,15 @@ def __getattr__(name): from PySide2.QtWidgets import * elif PYSIDE6: from PySide6.QtGui import QActionGroup, QShortcut, QUndoCommand - from PySide6.QtWidgets import * - from qtpy.QtGui import QAction # See spyder-ide/qtpy#461 + if parse(_qt_version) < parse("6.4"): + # Make `QAction.setShortcut` and `QAction.setShortcuts` compatible with Qt>=6.4 + # See spyder-ide/qtpy#461 + from qtpy.QtGui import QAction + else: + from PySide6.QtGui import QAction + + from PySide6.QtWidgets import * # Attempt to import QOpenGLWidget, but if that fails, # don't raise an exception until the name is explicitly accessed.