Skip to content

Document that %gui qt currently forces Qt5 #14038

Open

Description

@kwsp

Currently, when users select qt with %gui qt or %matplotlib qt, IPython forces matplotlib to switch to Qt5Agg first, before matplotlib's qt_compat.py kicks in (which, if run on its own, can actually pick up the right Qt bindings installed).

"qt": "Qt5Agg",

def find_gui_and_backend(gui=None, gui_select=None):
"""Given a gui string return the gui and mpl backend.
Parameters
----------
gui : str
Can be one of ('tk','gtk','wx','qt','qt4','inline','agg').
gui_select : str
Can be one of ('tk','gtk','wx','qt','qt4','inline').
This is any gui already selected by the shell.
Returns
-------
A tuple of (gui, backend) where backend is one of ('TkAgg','GTKAgg',
'WXAgg','Qt4Agg','module://matplotlib_inline.backend_inline','agg').
"""
import matplotlib
if gui and gui != 'auto':
# select backend based on requested gui
backend = backends[gui]

This isn't documented and has caused me a lot of confusion and trouble (and will cause further trouble in the future as usage of Qt6 increases over Qt5):

I found out about this after spending months trying to work out why %matplotlib qt doesn't work when I have Qt6 bindings installed: matplotlib/matplotlib#25673 (comment)

I suggest we either explicitly document this in the IPython line magic docs, or we change this default behavior.

Relevant but not duplicate:

Activity

  1. kwsp commented on Apr 26, 2023

    @kwsp
    Author

    relevant comment from @tacaswell: #13859 (comment)

    By the way @tacaswell thank you I appreciate your great work on matplotlib (and qt_compat.py)

    IPython defaulting to Qt5Agg when users select qt completely sidesteps most of the logic in qt_compat.py which actually works!

  2. kwsp commented on Apr 28, 2023

    @kwsp
    Author

    took a look at the docs again and i'd say this is actually a bug

    %gui qt      # enable PyQt/PySide event loop integration
                 # with the latest version available.
    
  3. tacaswell commented on Apr 28, 2023

    @tacaswell
    Contributor

    I will advocate for a PR that changes L26 to QtAgg. It probably requires a bit of version gating on the version of Matplotlib for versions before and after we added the QtAgg backend.

  4. Gullumluvl commented on Jul 12, 2023

    @Gullumluvl

    Maybe related: in Ipython 8.14.0, running %matplotlib tk also prints "Installed qt5 event loop hook", as in issue #14006 . And then plots do not appear, except for a flashing instant when calling plt.close()...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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