Search code examples
qtbitmapqimageqpixmap

QT: Painting bitmap/PNG images to a QWidget


I am building a game using QT in c++. I have extended the QWidget class as a painting surface and have set up a thread to refresh the screen. What I need now is to load the sprite sheets from file, break them up into separate 64x64 pixel images, and then paint them to the screen. Does anyone have some advice for how I should go about doing this?

TIA


Solution

  • Some QPainter::drawPixmap() variants has the option to specify the rectangle in the pixmap to be drawn. This will help you keeping the sprite sheets without breaking them up into small images.

    For repeated sprites, QPainter::drawPixmapFragments() probably will have better performance and also allow sub-image drawing.