void MainFr::paintEvent(QPaintEvent *){ QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); painter.setPen(Qt::darkGreen); painter.setBrush(QBrush(Qt::darkGreen, Qt::SolidPattern)); // Чем красим painter.drawRect(2, 2, Rect_size-2, Rect_size); connect(timer, SIGNAL(timeout()), this, SLOT(update())); timer->start(1000); painter.drawRect(455-Rect_size-2, 2, Rect_size, Rect_size); painter.drawRect(910-Rect_size-2, 2, Rect_size, Rect_size); painter.drawRect(1366-Rect_size-2, 2, Rect_size, Rect_size);}
C++ (Qt)void MainFr::paintEvent(QPaintEvent *){ static int x = 0; QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); painter.setPen(Qt::darkGreen); painter.setBrush(QBrush(Qt::darkGreen, Qt::SolidPattern)); // Чем красим // можно через switch if (x >= 0) painter.drawRect(2, 2, Rect_size-2, Rect_size); if (x >= 1) painter.drawRect(455-Rect_size-2, 2, Rect_size, Rect_size); if (x >= 2) painter.drawRect(910-Rect_size-2, 2, Rect_size, Rect_size); if (x >= 3) painter.drawRect(1366-Rect_size-2, 2, Rect_size, Rect_size); ++x; x = x%4;}
C++ (Qt)while(!asleep()) sheep++;
QTimer *timer = new QTimer(this); //... connect(timer, SIGNAL(timeout()), this, SLOT(update())); timer->start(1000);