11:mod: `.backend_qtagg `, :mod: `.backend_qtcairo `
22==============================================
33
4- **NOTE ** These backends are not (auto) documented here, to avoid adding a
5- dependency to building the docs.
4+ **NOTE ** These :ref: ` backends ` are not (auto) documented here, to avoid adding
5+ a dependency to building the docs.
66
77.. redirect-from :: /api/backend_qt4agg_api
88.. redirect-from :: /api/backend_qt4cairo_api
@@ -26,39 +26,39 @@ supported Python bindings per version -- `PyQt5
2626<https://www.riverbankcomputing.com/static/Docs/PyQt5/> `_ and `PySide2
2727<https://doc.qt.io/qtforpython-5/contents.html> `_ for Qt5 and `PyQt6
2828<https://www.riverbankcomputing.com/static/Docs/PyQt6/> `_ and `PySide6
29- <https://doc.qt.io/qtforpython/contents.html> `_ for Qt6 [# ]_. While both PyQt
29+ <https://doc.qt.io/qtforpython/contents.html> `_ for Qt6 [# ]_. Matplotlib's
30+ qtagg and qtcairo backends (``matplotlib.backends.backend_qtagg `` and
31+ ``matplotlib.backend.backend_qtcairo ``) support all these bindings, with common
32+ parts factored out in the ``matplotlib.backends.backend_qt `` module.
33+
34+ At runtime, these backends select the actual binding used as follows:
35+
36+ 1. If a binding's ``QtCore `` subpackage is already imported, that binding is
37+ selected (the order for the check is ``PyQt6 ``, ``PySide6 ``, ``PyQt5 ``,
38+ ``PySide2 ``).
39+ 2. If the :envvar: `QT_API ` environment variable is set to one of "PyQt6",
40+ "PySide6", "PyQt5", "PySide2" (case-insensitive), that binding is selected.
41+ (See also the documentation on :ref: `environment-variables `.)
42+ 3. Otherwise, the first available backend in the order ``PyQt6 ``, ``PySide6 ``,
43+ ``PyQt5 ``, ``PySide2 `` is selected.
44+
45+ In the past, Matplotlib used to have separate backends for each version of Qt
46+ (e.g. qt4agg/``matplotlib.backends.backend_qt4agg `` and
47+ qt5agg/``matplotlib.backends.backend_qt5agg ``). This scheme was dropped when
48+ support for Qt6 was added. For back-compatibility, qt5agg/``backend_qt5agg ``
49+ and qt5cairo/``backend_qt5cairo `` remain available; selecting one of these
50+ backends forces the use of a Qt5 binding. Their use is discouraged and
51+ ``backend_qtagg `` or ``backend_qtcairo `` should be preferred instead. However,
52+ these modules will not be deprecated until we drop support for Qt5.
53+
54+ While both PyQt
3055and Qt for Python (aka PySide) closely mirror the underlying C++ API they are
3156wrapping, they are not drop-in replacements for each other [# ]_. To account
3257for this, Matplotlib has an internal API compatibility layer in
3358`matplotlib.backends.qt_compat ` which covers our needs. Despite being a public
3459module, we do not consider this to be a stable user-facing API and it may
3560change without warning [# ]_.
3661
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-
6262.. [# ] There is also `PyQt4
6363 <https://www.riverbankcomputing.com/static/Docs/PyQt4/> `_ and `PySide
6464 <https://srinikom.github.io/pyside-docs/> `_ for Qt4 but these are no
0 commit comments