Unable to paint on Qt Widget, shows error “paintEngine: Should no longer be called”

前端 未结 1 692
醉话见心
醉话见心 2021-01-06 14:05

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

相关标签:
1条回答
  • 2021-01-06 14:45

    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.

    0 讨论(0)
提交回复
热议问题