Hi everyone,
i am working on a project where i need to draw lot of polygons. Is there any way to draw it without Timer? I am using QPainter... My problem is that i dont know how to draw a lot of polygons in short time, miliseconds.

Here is my code,
Qt Code:
  1. #include "widget.h"
  2. #include "ui_widget.h"
  3. #include "polygonpoints.h"
  4.  
  5.  
  6. Widget::Widget(QWidget *parent) :
  7. QWidget(parent),
  8. ui(new Ui::Widget)
  9. {
  10. ui->setupUi(this);
  11.  
  12.  
  13. timer = new QTimer(this);
  14. connect(timer, SIGNAL(timeout()), this, SLOT(AdvanceState()));
  15. timer->start(1);
  16.  
  17. }
  18.  
  19. Widget::~Widget()
  20. {
  21. delete ui;
  22. }
  23. void Widget::AdvanceState(){
  24. this->setAttribute(Qt::WA_NoSystemBackground,true);
  25. if(brojac<300){
  26. update();
  27. std::cout << ++brojac << std::endl;
  28. }
  29. }
  30.  
  31. void Widget::paintEvent(QPaintEvent *event)
  32. {
  33.  
  34. //std::cout << ++brojac << std::endl;
  35. QPainter painter(this);
  36. painter.setRenderHint(QPainter::Antialiasing, true);
  37. int N=9; // broj vrhova
  38. x.set_x(N);
  39. x.generate();
  40. //int N = 4; //broj vrhova
  41. QPointF *points = new QPointF[N];
  42. for(int i = 0; i < N; ++i){
  43. points[i].setX(x.vertices[i].get(0));
  44. points[i].setY(x.vertices[i].get(1));
  45. }
  46.  
  47. painter.setPen(Qt::NoPen);
  48. painter.setBrush(QBrush(QColor(qrand() % 255, qrand() % 255, qrand() % 255, 128)));
  49. painter.drawPolygon(points,N);
  50.  
  51. delete[] points;
  52.  
  53. }
To copy to clipboard, switch view to plain text mode