Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to use QPainter in sub-thread ?
MartinChan 0 last edited by
I have a question about QPainter. As we know :
- QPainter could only be used in a paintEvent();
- A paintEvent() is a over-ride function that only a QWidget has.
- A QWidget is a UI member, and qt's ui could only be in main thread.
So , does that mean u could only use QPainter in main thread ?? How could I draw a QImage in backstage ?
QPainter could only be used in a paintEvent();
This is a wrong assumption. See documentation (http://doc.qt.io/qt-5/qpainter.html):
"Warning: When the paintdevice is a widget, QPainter can only be used inside a paintEvent() function or in a function called by paintEvent()."
If you want to paint on a QImage it should work in a thread.