Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. ######################################################################
  2. # Automatically generated by qmake (3.1) Wed Mar 29 15:18:09 2017
  3. ######################################################################
  4.  
  5. TEMPLATE = app
  6. TARGET = qimageBehaviorForStackOverflowQuestion
  7. INCLUDEPATH += .
  8. QT += widgets
  9.  
  10. # Input
  11. HEADERS += qimageBehaviorForStackOverflowQuestion.h
  12. SOURCES += qimageBehaviorForStackOverflowQuestion.cpp
  13.  
  14. #include <iostream>
  15. #include <QApplication>
  16. #include <QWidget>
  17. #include <QTimer>
  18. #include <QPainter>
  19. #include <QPushButton>
  20. #include <QImage>
  21. #include <QTime>
  22.  
  23. class MyWidget : public QWidget {
  24. Q_OBJECT
  25. private:
  26. QImage *image;
  27. int px, py;
  28. uchar d[100*100*4];
  29. QTimer *timer;
  30. QTime time;
  31. public:
  32. MyWidget();
  33. void paintEvent(QPaintEvent * event);
  34. public slots:
  35. void doPaint();
  36. };
  37.  
  38. #include "qimageBehaviorForStackOverflowQuestion.h"
  39.  
  40. int my_counter = 0;
  41.  
  42. MyWidget::MyWidget() : QWidget(0), px(0), py(0){
  43. image = new QImage(d, 100, 100, QImage::Format_ARGB32);
  44. for(int cnt = 0, a, r, g, b; cnt < 100*100*4;){
  45. a = 255; //alpha
  46. r = 0; //red
  47. g = 0; //green
  48. b = 0; //blue
  49.  
  50. d[cnt] = b; cnt++;
  51. d[cnt] = g; cnt++;
  52. d[cnt] = r; cnt++;
  53. d[cnt] = a; cnt++;
  54. }
  55. // connect QTimer.timeout to my doPaint method
  56. timer = new QTimer();
  57. connect(timer, SIGNAL(timeout()), this, SLOT(doPaint()));
  58. timer->start(1);
  59. };
  60.  
  61. void MyWidget::doPaint(){
  62. // manipulate the positions of the points
  63. if(px < 100){
  64. int cnt = 0, b = 255, g = 255, r = 255, a = 255;
  65. d[4 * px + cnt] = b; cnt++;
  66. d[4 * px + cnt] = g; cnt++;
  67. d[4 * px + cnt] = r; cnt++;
  68. d[4 * px + cnt] = a; cnt++;
  69. px++;
  70. }
  71. // update the window
  72. update();
  73. };
  74.  
  75. void MyWidget::paintEvent(QPaintEvent * event){
  76. QPainter painter(this);
  77. painter.drawImage(0, 0, *image);
  78. }
  79.  
  80. int main(int argc, char *argv[]){
  81. QApplication app(argc, argv);
  82. MyWidget *widget = new MyWidget();
  83. widget->show();
  84. return app.exec();
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement