I am having problems with two different objects I can paint to (one for display and one for temporary holding of an image). I can paint to a widget and to an image separately, but not sure how to paint the same image to the widget and to a QImage residing inside the widget. I would like the widget and QImage to be updated during the same trigger event.

When I try this code, I get:
QRasterPaintEnginer::begin: Unsupported image format (3)
QPainter::begin(): Returned false
QPainter::end: Painter not active, aborted

I understand it is from having two QPainters in the paintEvent. I want full_img to be holder of the image, move the bottom 10 rows of the image to the top using drawImage on the painter, then save or paint the image I just painted to the widget to full_img.


Qt Code:
  1. // myMI.h
  2. #include <QWidget>
  3. class MarqueeImage : public QWidget
  4. {
  5. Q_OBJECT
  6. public:
  7. MarqueeImage(QWidget *parent = 0);
  8.  
  9. protected slots:
  10. void paintEvent(QPaintEvent *event);
  11.  
  12. private:
  13. QImage top_img; // top part of the image minus 10 lines
  14. QImage bot_img; // bottom 10 lines
  15. QImage *full_img; // temporary image
  16. int myheight; // height of image
  17. int mywidth; // width of image
  18. int line_shift; // bottom 10 lines
  19. };
  20.  
  21. // myMI.cpp
  22. #include “myMI.h”
  23. #include <QPainter>
  24. #include <QTimer>
  25.  
  26. MarqueeImage::MarqueeImage(QWidget *parent)
  27. : QWidget(parent)
  28. {
  29. mywidth = 200; //bitmap width
  30. myheight = 300; //bitmap height
  31. line_shift = 10; //number of lines being moved from bottom to top
  32.  
  33. full_img = new QImage();
  34. full_img->load(“mybmp.bmp”);
  35.  
  36. QTimer *timer = new QTimer(this);
  37. connect(timer, SIGNAL(timeout()), this, SLOT(update()));
  38. timer->start(500);
  39. }
  40.  
  41. void MarqueeImage::paintEvent(QPaintEvent *)
  42. {
  43. QPainter painter(this);
  44. top_img = full_img->copy(0, 0, mywidth-1, myheight-shift-1);
  45. bot_img = full_img->copy(0, myheight-line_shift-1, mywidth-1, shift);
  46. painter.drawImage(0, 0, bot_img);
  47. painter.drawImage(0, shift, top_img);
  48.  
  49. // This is where it doesn’t work
  50. QPainter paint_all(full_img);
  51. paint_all.drawImage(0, 0, bot_img);
  52. paint_all.drawImage(0, shift, top_img);
  53.  
  54. }
  55.  
  56.  
  57. // main.cpp
  58. #include <QApplication>
  59. #include “myMI.h”
  60.  
  61. int main(int argc, char *argv[])
  62. {
  63. Qapplication app(argc, argv);
  64. MarqueeImage myMI;
  65. myMI.show();
  66. return app.exec();
  67. }
To copy to clipboard, switch view to plain text mode