void Glass::paintEvent(QPaintEvent *event){ QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); painter.setBrush(QBrush(Qt::red, Qt::DiagCrossPattern)); painter.setPen(QPen(Qt::blue, 3, Qt::DashLine)); painter.drawRect(QRect(10, 10, 110, 70));}
void Glass::paintEvent(QPaintEvent *event){ QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); painter.setBrush(QBrush(Qt::red, Qt::DiagCrossPattern)); painter.setPen(QPen(Qt::blue, 3, Qt::DashLine)); int x=10; int y = 10; painter.drawRect(QRect(x, y, 110, 70)); for (int i=0; i<10; i++){ x = x + 10; y = y + 10; painter.drawRect(QRect(x, y, 110, 70)); }}
#include "glass.h"int i = 1;Glass::Glass(){ timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(mover())); timer->start(50);}void Glass::paintEvent(QPaintEvent *event){ QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); painter.setBrush(QBrush(Qt::red, Qt::DiagCrossPattern)); painter.setPen(QPen(Qt::blue, 3, Qt::DashLine)); int x=10; int y = 10; painter.drawRect(showRect());}QRect Glass::showRect(){ QRect rect(20, 20, 20, 20); double x = i; double y = i; i = i + 2; rect.moveBottomRight(QPoint(x, y)); return rect;}void Glass::mover(){ update();}