#include <QtGui>
{
public:
{
setAttribute(Qt::WA_NoSystemBackground, true);
setAttribute(Qt::WA_StaticContents, true);
first = true;
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(500);
}
{
if (first)
{
painter.setBrush(Qt::yellow);
painter.drawRect(this->rect());
first = false;
}
else
{
painter.setPen(Qt::red);
QPoint p
(qrand
() % this
->width
(), qrand
() % this
->height
());
painter.
drawRect(QRect(p.
x(), p.
y(),
10,
10));
}
}
bool first;
};
int main(int argc, char **argv)
{
test t;
t.show();
return app.exec();
}
#include <QtGui>
class test : public QWidget
{
public:
test(QWidget *parent = 0) : QWidget(parent)
{
setAttribute(Qt::WA_NoSystemBackground, true);
setAttribute(Qt::WA_StaticContents, true);
first = true;
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(500);
}
void paintEvent(QPaintEvent */*event*/)
{
QPainter painter(this);
if (first)
{
painter.setBrush(Qt::yellow);
painter.drawRect(this->rect());
first = false;
}
else
{
painter.setPen(Qt::red);
QPoint p(qrand() % this->width(), qrand() % this->height());
painter.drawRect(QRect(p.x(), p.y(), 10, 10));
}
}
bool first;
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
test t;
t.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks