I tried the QOpenGLWidget example described here: https://stackoverflow.com/a/31524956/4564882
but I get only a black widget. The code is exactly the same. this the code
In my case, my laptop uses NVIDIA external graphics card. So I went to NVIDIA Control Panel -> Manage 3D Settings -> Program Settings, and then selected "high-performance" for the .EXE file. This worked.