Search code examples
c++qtoff-screen

Qt create offscreen image then copy parts to onscreen?


I'm using Qt5.5, I want to create an offscreen image then copy specific parts of the offscreen image back to onscreen (visible) area.

Can anyone point me to a good example on how to create an offscreen image of a specific size, draw something on it, then copy a specific part of it (rectangle) from the offscreen image to the visible area.


Solution

  • I think you can create a QPixmap and then draw your image using a QPainter built on it...

    Something like:

      QPixmap pix(500,500);    
      QPainter paint(&pix);
      paint.setPen(QPen(QColor(255,34,255,255)));
      paint.drawRect(15,15,100,100);
    

    Then, you can draw a QPixmap on the screen as usual (in QML or Widget-based application).