I have created a widget using Qt Creator such a way that it has two sub windows inside a main window and some push buttons to load, save images, set pen width and color to p
All painting on a widget must happen in the paintEvent()
function, and you are trying to paint outside of it - that won't work.
You must either find a way to put all your drawing calls inside the paintEvent()
function, or draw on a buffer, for example a QPixmap
and then draw that pixmap onto the widget in the paintEvent()
When you draw on a buffer you can draw from everywhere, the limitation is only for widget drawing. For pixmaps you (usually) must draw from the main thread, if you want to draw from another thread, use QImage
instead.