Detailed Description
The QThumbnail class provides thumbnails of large images.
A thumbnail is a small version of an image loaded from a file or QIODevice.
Thumbnail pixmaps are generated by calling pixmap(maximum_size). Usually, aspect ratio is preserved, so the actualSize() of the image may have a smaller width or height than the maximum size.
For many image formats, thumbnails are loaded by methods more efficient than the naive method of simply loading the entire image and scaling it down. For other formats, the naive method is used.
This code paints the contents of image.jpg centered on the calling widget:
QPainter painter( this );
QThumbnail thumbnail( "image.jpg" );
offset = (size() - thumbnail.actualSize(size())) / 2;
painter.drawPixmap( offset.width(), offset.height(), thumbnail.pixmap(size()));
Member Function Documentation
QThumbnail::QThumbnail ( const QString & fileName )
Constructs the thumbnail for the given image fileName. The file is not loaded at this time, but it is opened.
QThumbnail::QThumbnail ( QIODevice * device )
Constructs the thumbnail for an image to be read from the given io device.
QThumbnail::~QThumbnail ()
Destroys the thumbnail.
QSize QThumbnail::actualSize ( const QSize & size = QSize(), Qt::AspectRatioMode mode = Qt::KeepAspectRatio )
Returns the actual size of the thumbnail for the requested size and mode. An invalid size is returned if the image is not able to be read. The whole image may be loaded if the image handler does not support the QImageIOHandler::Size option.
If size is invalid the function returns the size as defined by QImageIOHandler::Size. This can be used to prevent that the image is scaled up when calling QThumbnail::pixmap():
thumbnail.pixmap(
thumbnail.actualSize(
maxsize.boundedTo(
thumbnail.actualSize(QSize())
)
)
)
See also pixmap().
QPixmap QThumbnail::pixmap ( const QSize & size, Qt::AspectRatioMode mode = Qt::KeepAspectRatio, Qt::TransformationMode transformationMode = Qt::FastTransformation )
Returns a pixmap with the requested size and mode. A null pixmap is returned if the image cannot be loaded.
The pixmap will be generated by scaling the image as it is being loaded where possible. This is reliant on the support for the QImageIOHandler::ScaledSize option in the image handler. If the option is not supported the whole image will be loaded and then scaled with the requested transformationMode.
See also actualSize().