Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mywidget.h"
- #include <QPainter>
- MyWidget::MyWidget(QWidget *parent) : QWidget(parent)
- {
- timer = new QTimer(this); // destruction is made by the Qt framework
- connect(timer, SIGNAL(timeout()), this, SLOT(repaint()));
- timer->start(50);
- }
- MyWidget::~MyWidget() {
- delete[] buffer;
- }
- void MyWidget::paintEvent(QPaintEvent *e) {
- fillBuffer();
- QImage img((unsigned char *)buffer, width(), height(), QImage::Format_RGB32);
- QPainter p(this);
- p.drawImage(0, 0, img);
- }
- void MyWidget::fillBuffer() {
- if (buffer == nullptr) {
- buffer = new uint32_t[width() * height()];
- for(int i = 0; i < width() * height(); i++) {
- buffer[i] = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement