Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ######################################################################
- # Automatically generated by qmake (3.1) Wed Mar 29 15:18:09 2017
- ######################################################################
- TEMPLATE = app
- TARGET = qimageBehaviorForStackOverflowQuestion
- INCLUDEPATH += .
- QT += widgets
- # Input
- HEADERS += qimageBehaviorForStackOverflowQuestion.h
- SOURCES += qimageBehaviorForStackOverflowQuestion.cpp
- #include <iostream>
- #include <QApplication>
- #include <QWidget>
- #include <QTimer>
- #include <QPainter>
- #include <QPushButton>
- #include <QImage>
- #include <QTime>
- class MyWidget : public QWidget {
- Q_OBJECT
- private:
- QImage *image;
- int px, py;
- uchar d[100*100*4];
- QTimer *timer;
- QTime time;
- public:
- MyWidget();
- void paintEvent(QPaintEvent * event);
- public slots:
- void doPaint();
- };
- #include "qimageBehaviorForStackOverflowQuestion.h"
- int my_counter = 0;
- MyWidget::MyWidget() : QWidget(0), px(0), py(0){
- image = new QImage(d, 100, 100, QImage::Format_ARGB32);
- for(int cnt = 0, a, r, g, b; cnt < 100*100*4;){
- a = 255; //alpha
- r = 0; //red
- g = 0; //green
- b = 0; //blue
- d[cnt] = b; cnt++;
- d[cnt] = g; cnt++;
- d[cnt] = r; cnt++;
- d[cnt] = a; cnt++;
- }
- // connect QTimer.timeout to my doPaint method
- timer = new QTimer();
- connect(timer, SIGNAL(timeout()), this, SLOT(doPaint()));
- timer->start(1);
- };
- void MyWidget::doPaint(){
- // manipulate the positions of the points
- if(px < 100){
- int cnt = 0, b = 255, g = 255, r = 255, a = 255;
- d[4 * px + cnt] = b; cnt++;
- d[4 * px + cnt] = g; cnt++;
- d[4 * px + cnt] = r; cnt++;
- d[4 * px + cnt] = a; cnt++;
- px++;
- }
- // update the window
- update();
- };
- void MyWidget::paintEvent(QPaintEvent * event){
- QPainter painter(this);
- painter.drawImage(0, 0, *image);
- }
- int main(int argc, char *argv[]){
- QApplication app(argc, argv);
- MyWidget *widget = new MyWidget();
- widget->show();
- return app.exec();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement