Skip to content

Instantly share code, notes, and snippets.

@DavidLudwig
Created March 15, 2019 16:02
Show Gist options
  • Save DavidLudwig/6d460e1c67e9f44ca754e1ef6868ef28 to your computer and use it in GitHub Desktop.
Save DavidLudwig/6d460e1c67e9f44ca754e1ef6868ef28 to your computer and use it in GitHub Desktop.
#include <QtWidgets>
static uchar pixel_buffer[512 * 512 * 4];
class MyWidget : public QWidget {
Q_OBJECT
private:
QImage * _image = nullptr;
public:
MyWidget() {
resize(512, 512);
setWindowTitle(tr("My App"));
memset(pixel_buffer, 0, sizeof(pixel_buffer));
_image = new QImage(pixel_buffer, 512, 512, QImage::Format_RGB32);
}
protected:
void paintEvent(QPaintEvent *event) override {
QPainter painter(this);
painter.drawImage(0, 0, *_image);
}
};
int main(int argc, char **argv) {
QApplication app(argc, argv);
MyWidget v;
v.show();
return app.exec();
}
#include "qt_draw_image.moc"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment