Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scaled QPixmap looks bad

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?

like image 427
iTayb Avatar asked Dec 15 '12 09:12

iTayb


People also ask

Why is my pixmap drawing at a different scale set?

In some cases it can be more beneficial to draw the pixmap to a painter with a scale set rather than scaling the pixmap. This is the case when the painter is for instance based on OpenGL or when the scale factor changes rapidly. See also isNull () and Pixmap Transformations. This is an overloaded function.

What is the difference between qbitmap and qimage and qpicture?

Qt provides four classes for handling image data: QImage, QPixmap, QBitmap and QPicture. QImage is designed and optimized for I/O, and for direct pixel access and manipulation, while QPixmap is designed and optimized for showing images on screen. QBitmap is only a convenience class that inherits QPixmap, ensuring a depth of 1.

What is the qpixmap class?

The QPixmap class is an off-screen image representation that can be used as a paint device. More... Qt provides four classes for handling image data: QImage, QPixmap, QBitmap and QPicture. QImage is designed and optimized for I/O, and for direct pixel access and manipulation, while QPixmap is designed and optimized for showing images on screen.

How to detach a pixmap in Qt?

See also defaultDepth () and Pixmap Information. Detaches the pixmap from shared pixmap data. A pixmap is automatically detached by Qt whenever its contents are about to change. This is done in almost all QPixmap member functions that modify the pixmap ( fill (), fromImage (), load (), etc.), and in QPainter::begin () on a pixmap.


Video Answer


2 Answers

Use the transformMode parameter:

pixmap = QtGui.QPixmap(r'pics\cdaudio.png').scaled(100, 100, transformMode=QtCore.Qt.SmoothTransformation)
like image 184
iTayb Avatar answered Oct 16 '22 21:10

iTayb


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);
like image 44
Robert Avatar answered Oct 16 '22 20:10

Robert