Scaled QPixmap looks bad
Asked Answered
S

3

7

I have the following widget:

pixmap = QtGui.QPixmap(r'pics\cdaudio.png').scaled(100, 100)

The image is scaled down, from 256x256. It looks pretty choppy:

enter image description here

How can I scale it smoothly from within Qt?

Sexton answered 15/12, 2012 at 9:46 Comment(2)
Did you take a look at the docs by any chance?Mittel
Didn't know that scaled gets parameters beside the resolution. ThanksSexton
S
19

Use the transformMode parameter:

pixmap = QtGui.QPixmap(r'pics\cdaudio.png').scaled(100, 100, transformMode=QtCore.Qt.SmoothTransformation)
Sexton answered 15/12, 2012 at 9:57 Comment(0)
A
5

According to @iTayb, here's what I came up with:

// Scale the source to the requested size with 
//  the KeepAspectRatio as aspectMode & SmoothTransformation as mode
*source = source->scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation);
target->setPixmap(*source);
Apoloniaapolune answered 6/6, 2014 at 5:20 Comment(0)
K
0

Why not using the SVG format (and the Qt SVG module for this) if possible ?

Knightly answered 16/12, 2012 at 2:30 Comment(1)
Who said that my source is a SVG?Sexton

© 2022 - 2024 — McMap. All rights reserved.