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:
How can I scale it smoothly from within Qt?
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.
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.
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.
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.
Use the transformMode
parameter:
pixmap = QtGui.QPixmap(r'pics\cdaudio.png').scaled(100, 100, transformMode=QtCore.Qt.SmoothTransformation)
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With