Hello, in this program I want to blinking of the rectangle.in this way: First, Blue rectangle show.and after 500 msec,Red rectangle show.but, when I run this program,I see A high pause and then red rectangle show and Not Blink well.
Qt Code:
  1. #include "lines.h"
  2. #include <QPainter>
  3. #include <QThread>
  4. Lines::Lines(QWidget *parent)
  5. : QWidget(parent)
  6. {
  7.  
  8. }
  9.  
  10. void Lines::paintEvent(QPaintEvent *e)
  11. {
  12. for(int i=1;i<=10;i++)
  13. {
  14. Q_UNUSED(e);
  15.  
  16. QPainter qp(this);
  17. QBrush brush(Qt::blue);
  18. qp.setBrush(brush);
  19. qp.drawRect(100,100,200,200);
  20. QThread::msleep(500);
  21. brush.setColor(Qt::red);
  22. qp.setBrush(brush);
  23. qp.drawRect(100,100,200,200);
  24. }}
To copy to clipboard, switch view to plain text mode