Hi i am working on college task that involve a recursion drawing question and i am working with Qt.
my problem when the drawing function begin, the gui freezing until drawing finish,even though i used multi threading .
is there any way to avoid freezing while repainting main window ???
here is the code:
Qt Code:
  1. class draw:public QThread
  2. {
  3. public :
  4. QWidget *t;
  5. draw(){}
  6. void run()
  7. {
  8. Drawing(10,40,0,3.1415926535897932384626433832795/4,200,200,d);
  9. }
  10.  
  11. void Drawing(int n,double d,double q1,double q2,int x,int y,QPainter *dr)
  12. {
  13. if (n > 0)
  14. {
  15. int x1 = x - (sin(q1) * d);
  16. int y1 = y - (cos(q1) * d);
  17. dr->drawLine(x, y, x1, y1);
  18. t->repaint();
  19. int x2 = x1- (cos(q1) * d);
  20. int y2 = y1 + (sin(q1) * d);
  21. dr->drawLine(x1, y1, x2, y2);
  22. t->repaint();
  23. int x3 = x2 + (sin(q1) * d);
  24. int y3 = y2 + (cos(q1) * d);
  25. dr->drawLine(x2 , y2 , x3 , y3);
  26. t->repaint();
  27. dr->drawLine(x3 , y3 , x , y );
  28. t->repaint();
  29. double d1 = d / sqrt( 2.0 ); //d1 = d/?2
  30. int x4 = x1 - ( cos(q2) * d1);
  31. int y4 = y1 - ( sin(q2) * d1);
  32. Drawing(n - 1, d1, q1 - 3.1415926535897932384626433832795/4, q2 + 3.1415926535897932384626433832795/4 , x1 , y1,dr);
  33.  
  34. Drawing(n - 1, d1, q1 + 3.1415926535897932384626433832795/4, q2 - 3.1415926535897932384626433832795/4 , x4 , y4,dr);
  35. }
  36. }
  37. };
  38.  
  39.  
  40. void MainWindow::on_pushButton_clicked()
  41. {
  42. image=new QPixmap(this->geometry().width(),this->geometry().height());
  43. image->fill(this,0,0);
  44. dr=new QPainter(this->image);
  45. r=this->geometry();
  46. draw d;
  47. d.d=dr;
  48. d.t=this;
  49. d.run();
  50. delete dr;
  51. }
  52.  
  53.  
  54.  
  55.  
  56.  
  57. void MainWindow::paintEvent(QPaintEvent *e)
  58. {
  59. QPainter p(this);
  60. p.drawPixmap(r,*this->image);
  61. }
To copy to clipboard, switch view to plain text mode