Home > Software engineering >  How to resize QPixmap without content?
How to resize QPixmap without content?

Time:07-26

I want to set a specific size to QPixmap but keep content in the same place and the same size

For example: original, target

CodePudding user response:

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);
  • Related