I have no idea what a "quadratic QGraphicsPixmapItem" or "quadratic image" is, perhaps you meant square. Here is one way to get your letter (or pillar) boxed pixmap.
QPixmap source
("test.png");
// say 400x300 dest.fill(Qt::black);
QPixmap resized
= source.
scaled(dest.
size(), Qt
::KeepAspectRatio);
if (resized.width() < dest.width())
p.drawPixmap( (dest.width() - resized.width())/2, 0, resized);
else
p.drawPixmap( 0, (dest.height() - resized.height())/2, resized);
p.end();
dest.save("output.png");
QPixmap source("test.png"); // say 400x300
QPixmap dest(512, 512);
dest.fill(Qt::black);
QPixmap resized = source.scaled(dest.size(), Qt::KeepAspectRatio);
QPainter p(&dest);
if (resized.width() < dest.width())
p.drawPixmap( (dest.width() - resized.width())/2, 0, resized);
else
p.drawPixmap( 0, (dest.height() - resized.height())/2, resized);
p.end();
dest.save("output.png");
To copy to clipboard, switch view to plain text mode
Bookmarks