Skip to content

silx resetting matplotlib Qt binding with Qt6 #4472

@malte-storm

Description

@malte-storm

In silx, the matplotlib backend is set to Qt5Agg also for Qt6 bindings:

https://github.com/silx-kit/silx/blob/main/src/silx/gui/utils/matplotlib.py:

# This must be performed before any import from matplotlib
if qt.BINDING in ("PySide6", "PyQt6", "PyQt5"):
    matplotlib.use("Qt5Agg", force=False)
    from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg  # noqa

with similar code in fabio https://github.com/silx-kit/fabio/blob/main/src/fabio/qt/matplotlib.py

whereas pyFAI (in https://github.com/silx-kit/pyFAI/blob/main/src/pyFAI/gui/matplotlib.py) explicitly uses the QtAgg binding:

elif qt.BINDING in ('PyQt6', 'PySide6', 'PyQt5', 'PySide2'):
    _configure('QtAgg', check=_check_matplotlib)
    from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg  # noqa

When executing the simple code with for example QT_API=pyside6:

import silx.gui.utils.matplotlib
import pyFAI.gui.matplotlib

This raises a single warning on the command line

WARNING:pyFAI.gui.matplotlib:Matplotlib already loaded with backend `Qt5Agg`, setting its backend to `QtAgg` may not work!

or two in ipython:

Cannot switch Qt versions for this session; will use qt6.
WARNING:pyFAI.gui.matplotlib:Matplotlib already loaded with backend `Qt5Agg`, setting its backend to `QtAgg` may not work!

I assume the use of the Qt5Agg backend is not deliberate qith Qt6 bindings? If there are no further dependencies, I would be happy to create a pull request for a fix, but I wanted to check whether there is a specific reason for pinning the backend first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions