|
1 | 1 | :mod:`.backend_qtagg`, :mod:`.backend_qtcairo`
|
2 | 2 | ==============================================
|
3 | 3 |
|
4 |
| -**NOTE** These backends are not documented here, to avoid adding a dependency |
5 |
| -to building the docs. |
| 4 | +**NOTE** These backends are not (auto) documented here, to avoid adding a |
| 5 | +dependency to building the docs. |
6 | 6 |
|
7 | 7 | .. redirect-from:: /api/backend_qt4agg_api
|
8 | 8 | .. redirect-from:: /api/backend_qt4cairo_api
|
9 | 9 | .. redirect-from:: /api/backend_qt5agg_api
|
10 | 10 | .. redirect-from:: /api/backend_qt5cairo_api
|
11 | 11 |
|
| 12 | +.. module:: matplotlib.backends.qt_compat |
| 13 | +.. module:: matplotlib.backends.backend_qt |
12 | 14 | .. module:: matplotlib.backends.backend_qtagg
|
13 | 15 | .. module:: matplotlib.backends.backend_qtcairo
|
14 | 16 | .. module:: matplotlib.backends.backend_qt5agg
|
15 | 17 | .. module:: matplotlib.backends.backend_qt5cairo
|
| 18 | + |
| 19 | +.. _QT_bindings: |
| 20 | + |
| 21 | +Qt Bindings |
| 22 | +----------- |
| 23 | + |
| 24 | +There are currently 2 actively supported Qt versions, Qt5 and Qt6, and two |
| 25 | +supported Python bindings per version -- `PyQt5 |
| 26 | +<https://www.riverbankcomputing.com/static/Docs/PyQt5/>`_ and `PySide2 |
| 27 | +<https://doc.qt.io/qtforpython-5/contents.html>`_ for Qt5 and `PyQt6 |
| 28 | +<https://www.riverbankcomputing.com/static/Docs/PyQt6/>`_ and `PySide6 |
| 29 | +<https://doc.qt.io/qtforpython/contents.html>`_ for Qt6 [#]_. While both PyQt |
| 30 | +and Qt for Python (aka Pyside) closely mirror the underlying c++ API they are |
| 31 | +wrapping, they are not drop-in replacements for each other [#]_. To account |
| 32 | +for this, Matplotlib has an internal API compatibility layer in |
| 33 | +`matplotlib.backends.qt_compat` which covers our needs. Despite being a public |
| 34 | +module, we do not consider this to be a stable user-facing API and it may |
| 35 | +change without warning [#]_. |
| 36 | + |
| 37 | +Previously Matplotlib's Qt backends had the Qt version number in the name, both |
| 38 | +in the module and the :rc:`backend` value |
| 39 | +(e.g. ``matplotlib.backends.backend_qt4agg`` and |
| 40 | +``matplotlib.backends.backend_qt5agg``), however as part of adding support for |
| 41 | +Qt6 we were able to support both Qt5 and Qt6 with a single implementation with |
| 42 | +all of the Qt version and binding support handled in |
| 43 | +`~matplotlib.backends.qt_compat`. A majority of the renderer agnostic Qt code |
| 44 | +is now in `matplotlib.backends.backend_qt` with specialization for AGG in |
| 45 | +``backend_qtagg`` and cairo in ``backend_qtcairo``. |
| 46 | + |
| 47 | +The binding is selected at run time based on what bindings are already imported |
| 48 | +(by checking for the ``QtCore`` sub-package), then by the :envvar:`QT_API` |
| 49 | +environment variable, and finally by the :rc:`backend`. In all cases when we |
| 50 | +need to search, the order is ``PyQt6``, ``PySide6``, ``PyQt5``, ``PySide2``. |
| 51 | +See :ref:`QT_API-usage` for usage instructions. |
| 52 | + |
| 53 | +The ``backend_qt5``, ``backend_qt5agg``, and ``backend_qt5cairo`` are provided |
| 54 | +and force the use of a Qt5 binding for backwards compatibility. Their use is |
| 55 | +discouraged (but not deprecated) and ``backend_qt``, ``backend_qtagg``, or |
| 56 | +``backend_qtcairo`` should be preferred instead. However, these modules will |
| 57 | +not be deprecated until we drop support for Qt5. |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | +.. [#] There is also `PyQt4 |
| 63 | + <https://www.riverbankcomputing.com/static/Docs/PyQt4/>`_ and `PySide |
| 64 | + <https://srinikom.github.io/pyside-docs/>`_ for Qt4 but these are no |
| 65 | + longer supported by Matplotlib and upstream support for Qt4 ended |
| 66 | + in 2015. |
| 67 | +.. [#] Despite the slight API differences, the more important distinction |
| 68 | + between the PyQt and Qt for Python series of bindings is licensing. |
| 69 | +.. [#] If you are looking for a general purpose compatibility library please |
| 70 | + see `qtpy <https://github.com/spyder-ide/qtpy>`_. |
0 commit comments