diff --git a/lib/matplotlib/backends/backend_qt5.py b/lib/matplotlib/backends/backend_qt5.py index 7fe7ff3a476e..f70bf6f1dc5f 100644 --- a/lib/matplotlib/backends/backend_qt5.py +++ b/lib/matplotlib/backends/backend_qt5.py @@ -680,7 +680,6 @@ def destroy(self, *args): if self.window._destroying: return self.window._destroying = True - self.window.destroyed.connect(self._widgetclosed) if self.toolbar: self.toolbar.destroy() self.window.close() diff --git a/lib/matplotlib/backends/qt_compat.py b/lib/matplotlib/backends/qt_compat.py index 86beaf97a093..bb206c9ed3eb 100644 --- a/lib/matplotlib/backends/qt_compat.py +++ b/lib/matplotlib/backends/qt_compat.py @@ -102,7 +102,7 @@ _sip_imported = False # Now perform the imports. -if QT_API in (QT_API_PYQT, QT_API_PYQTv2, QT_API_PYQT5): +if QT_API in (QT_API_PYQT, QT_API_PYQTv2): try: import sip _sip_imported = True @@ -135,18 +135,20 @@ except: res = 'QVariant API v2 specification failed. Defaulting to v1.' _log.info(cond + res) - if QT_API == QT_API_PYQT5: - try: - from PyQt5 import QtCore, QtGui, QtWidgets - _getSaveFileName = QtWidgets.QFileDialog.getSaveFileName - except ImportError: - if _fallback_to_qt4: - # fell through, tried PyQt5, failed fall back to PyQt4 - QT_API = QT_API_PYQT - QT_RC_MAJOR_VERSION = 4 - else: - raise +if QT_API == QT_API_PYQT5: + try: + from PyQt5 import QtCore, QtGui, QtWidgets + _getSaveFileName = QtWidgets.QFileDialog.getSaveFileName + except ImportError: + if _fallback_to_qt4: + # fell through, tried PyQt5, failed fall back to PyQt4 + QT_API = QT_API_PYQT + QT_RC_MAJOR_VERSION = 4 + else: + raise + +if _sip_imported: # needs to be if so we can re-test the value of QT_API which may # have been changed in the above if block if QT_API in [QT_API_PYQT, QT_API_PYQTv2]: # PyQt4 API @@ -168,23 +170,6 @@ def _getSaveFileName(*args, **kwargs): # call to getapi() can fail in older versions of sip def _getSaveFileName(*args, **kwargs): return QtGui.QFileDialog.getSaveFileName(*args, **kwargs), None - try: - # Alias PyQt-specific functions for PySide compatibility. - QtCore.Signal = QtCore.pyqtSignal - try: - QtCore.Slot = QtCore.pyqtSlot - except AttributeError: - # Not a perfect match but works in simple cases - QtCore.Slot = QtCore.pyqtSignature - - QtCore.Property = QtCore.pyqtProperty - __version__ = QtCore.PYQT_VERSION_STR - except NameError: - # QtCore did not get imported, fall back to pyside - if QT_RC_MAJOR_VERSION == 5: - QT_API = QT_API_PYSIDE2 - else: - QT_API = QT_API_PYSIDE if QT_API == QT_API_PYSIDE2: @@ -211,6 +196,18 @@ def _getSaveFileName(*args, **kwargs): _getSaveFileName = QtGui.QFileDialog.getSaveFileName +if QT_API in (QT_API_PYQT, QT_API_PYQTv2, QT_API_PYQT5): + # Alias PyQt-specific functions for PySide compatibility. + QtCore.Signal = QtCore.pyqtSignal + try: + QtCore.Slot = QtCore.pyqtSlot + except AttributeError: + # Not a perfect match but works in simple cases + QtCore.Slot = QtCore.pyqtSignature + + QtCore.Property = QtCore.pyqtProperty + __version__ = QtCore.PYQT_VERSION_STR + # Apply shim to Qt4 APIs to make them look like Qt5 if QT_API in (QT_API_PYQT, QT_API_PYQTv2, QT_API_PYSIDE): '''Import all used QtGui objects into QtWidgets