How to set a specific size to the QPixmap and keep content in the same position and the same size?

Question:

I only want to resize the QPixmap, not the content.

Asked By: Matt Harason

||

Answers:

QPixmap newPixmap(newWidth, newHeight);
newPixmap.fill(Qt::black); // or the color you like... maybe you want Qt::transparent?
QPainter painter(&newPixmap);
painter.drawPixmap(0, 0, oldPixmap);
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.