I will not reprint. See the bean blog directly: https://www.devbean.net/2012/12/qt-study-road-2-paint-device/
It should be noted that it is very convenient to use OpenCV and OpenGL under Qt. You may need OpenCV for image processing, and you may need OpenGL for graphics drawing and rendering.