[PyQt] QOpenGLWidget

kristof.mulier at telenet.be kristof.mulier at telenet.be
Sun Sep 22 16:07:05 BST 2019


Hi, 

I'm building an application in PyQt5 for which I need to draw 2D live graphs. I'm looking for a way to render them with the GPU . 

1. First approach 
--------------------- 
My first approach was embedding matplotlib into PyQt5. Matplotlib is not so fast, because it relies on CPU-rendering only . 

2. Second approach 
------------------------ 
I build my own PyQt5 widget and override the paintEvent() method to draw a few thousand lines with the QPainter() to display the live graph. The graph points are stored in numpy arrays. I simply draw lines between the points. Unfortunately, QPainter() relies on the CPU. 

Right now, it looks like I have several options for GPU-based rendering: 

- QOpenGLWidget 
(see https://doc.qt.io/qt-5/qopenglwidget.html). From what I read on the Qt docs, it looks too good to be true. I would simply need to subclass QOpenGLWidget instead of QWidget . Apparently, I eveb don't have to change anything in the paintEvent() method. Is this real? Where are the pitfalls? 

- PyOpenGL 
Python bindings for OpenGL. I have no OpenGL experience. I found the following tutorial: https://www.labri.fr/perso/nrougier/python-opengl/ . Great, but I'm afraid to spend a lot of time on this. When I scroll through the tutorial, it appears to me that the focus is on 3D shapes. I don't need that. 

- QGraphicsView 
I remember reading something about QGraphicsView() in a StackOverflow answer. It would be a Qt class to draw lots of shapes. But can it handle thousands of tiny lines that form the live graph? Does it rely on the CPU or the GPU for rendering? 


Could you point me in the right direction please? 




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190922/b9b77776/attachment.html>


More information about the PyQt mailing list