Created
March 15, 2019 16:02
-
-
Save DavidLudwig/6d460e1c67e9f44ca754e1ef6868ef28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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