I'm attempting to create a simple animation in Qt through QPainter, currently i've been able to draw in my window, but i'm unable to figure out how i could draw the same thing periodically.
Here's my current code:
int main(int argc, char *argv[]){
QApplication a (argc, argv);
QLabel l;
Qpicture pi;
Qpainter p(&pi);
Qpen pen;
/*
Some ellipses and lines using p.drawLine and p.drawEllipse
*/
p.end();
l.setPicture(pi);
l.show();
return a.exec();
I've tried creating a thread, but i can't create a QApplication outside of main and if i try to give my painter, label, picture and pen to a thread, then it won't compile as they are private:
void PrintThread ( QLabel * l, QPicture * pi, Qpainter * p, QPen * pen){
/*
print lines and ellipses
*/
}
int main(int argc, char *argv[]){
QApplication a (argc, argv);
QLabel l;
Qpicture pi;
Qpainter p(&pi);
Qpen pen;
std::thread doPaint (PrintThread, l, pi, p, pen);
doPaint.join();
How would a sample code that draws anything (lines/ellipses) using Qpainter every X milliseconds look like?