help you fix your problem In drawGraph(), the call to update() posts an event notifying the widget to paint itself. You then clear the points and the drawGraph() call exits. After that, the event loop will process the update event and trigger a call to the paintEvent() but by then, there are no points in the vector of points to paint. Don't think of the paintEvent() as painting something permanent onto the widget once that will be displayed forever until you clear it and paint something else. The paintEvent() needs to be able to paint the widget from scratch whenever it needs to be redrawn. This is often due to a request from the system when the widget is moved, minimized and restored etc. This means your vector of points needs to remain until you no longer want a polygon to be displayed or the points are changed.
Why does QPainter clear the widget every time I use it?
I think the issue was by ths following , you have to redraw the widget content on each paintEvent, there's no other way. maybe in your case it woule be better to draw on a other paint device (QImage, QPixmap, QPicture, ...), and just paint that on each paint event.
How to draw QImage on QScrollArea? Did this, but have some minor problems QPainter::begin: Widget painting can only begi
With these it helps Question is, where do you want to paint: on ImageWidget, on imgDisplayLabel, or on scrollArea. If I interpret correctly, the warning is basically saying that, if you want to begin a painter on a widget, you should do it in THE same widget's paint event.
QPainter fillRect over geometry of widget in grid cell