pythonqt icon indicating copy to clipboard operation
pythonqt copied to clipboard

how can i use matplotlib by PyhtonQt in a qt/C++ application? Thanks

Open chenwenjingdev opened this issue 1 year ago • 1 comments

image

chenwenjingdev avatar Oct 26 '24 15:10 chenwenjingdev

mainwindow.cpp

image

chenwenjingdev avatar Oct 26 '24 15:10 chenwenjingdev

Well, first, did you install matplotlib into your embedded Python interpreter? Because it seems like you didn't. Perhaps you just need to extend the PYTHON_PATH for matplotlib to be found? This can be done with PythonQt::self()->addSysPath().

Second: Matplotlib is not prepared to work with PythonQt. In MeVisLab we patch matplotlib to make it work with PythonQt. These patches can be found here.

Third: To use matplotlib in an already running event loop (like you seem to do), you need additional support. In MeVisLab we currently use qasync, which we also patched to work with PythonQt. The patches can be found here. qasync is then initialized with the following code:

import qasync
import asyncio

qtLoop = qasync.QEventLoop()
asyncio.set_event_loop(qtLoop)
# this is a 'trick', we start the event loop BUT leave it to MeVisLab to call QApplication.exec()
qtLoop.run_forever_start()

usiems avatar Oct 29 '24 16:10 usiems