6.0.0-rc4Source

QPixmap Class

The QPixmap class is an image to paint and to show, such as a splash screen or a picture in a label. More…

Header#include <QPixmap>
CMaketarget_link_libraries(app PRIVATE Nt::Gui)
ModuleNt GUI C++ Classes
InheritsQPaintDevice

List of all members, including inherited members

Public Functions

QPixmap()
QPixmap(int width, int height)
QPixmap(const QSize &size)
QPixmap(const QString &fileName, const char *format = nullptr)
QPixmap(const QPixmap &other)
QPixmap(QPixmap &&other)
~QPixmap()
QPixmap &operator=(const QPixmap &other)
QPixmap &operator=(QPixmap &&other)
voidswap(QPixmap &other)
boolisNull() const
QSizesize() const
QRectrect() const
boolhasAlphaChannel() const
voidfill(const QColor &color = Qt::white)
QPixmapcopy(const QRect &rect = QRect()) const
QImagetoImage() const
boolload(const QString &fileName, const char *format = nullptr)
boolloadFromData(const uchar *data, uint len, const char *format = nullptr)
boolloadFromData(QByteArrayView data, const char *format = nullptr)
boolsave(const QString &fileName, const char *format = nullptr, int quality = -1) const
boolsave(QIODevice *device, const char *format = nullptr, int quality = -1) const

Reimplemented Public Functions

Static Public Members

QPixmapfromImage(const QImage &image)

Reimplemented Protected Functions

intmetric(PaintDeviceMetric metric) const
QPaintDevice *redirected(QPoint *offset) const

Detailed Description

A pixmap is a picture with an alpha channel that a QPainter paints on and that widgets show:

QPixmap picture(200, 100);
picture.fill(Qt::white);
QPainter painter(&picture);
painter.drawText(picture.rect(), Qt::AlignCenter, "Nt");
painter.end();
label->setPixmap(picture);

Pixmaps share their data: copying one is cheap, and it is copied when one of the copies is painted on.

See also QImage and QPainter.

Differences from Qt

A pixmap is a QImage in memory, not a resource of the window system. Files load and save through QImage, so they are PNG, BMP and JPEG, and the format is found from the contents of the file. There is no scaled(), transformed(), mask(), QPixmapCache or device pixel ratio.

Member Function Documentation

QPixmap::QPixmap()

Constructs a null pixmap.

See also isNull().

QPixmap::QPixmap(int width, int height)

Constructs a pixmap of width by height pixels. Its contents are transparent until it is filled or painted on.

[explicit] QPixmap::QPixmap(const QSize &size)

Constructs a pixmap of the given size, transparent.

[explicit] QPixmap::QPixmap(const QString &fileName, const char *format = nullptr)

Constructs a pixmap from the image file fileName. The pixmap is null if the file cannot be loaded. The format is ignored, as in QImage::load().

See also load().

QPixmap::QPixmap(const QPixmap &other)

Constructs a pixmap that shares the data of other.

QPixmap::QPixmap(QPixmap &&other)

Constructs a pixmap that takes the data of other.

[override] QPixmap::~QPixmap()

Destroys the pixmap.

QPixmap QPixmap::copy(const QRect &rect = QRect()) const

Returns a copy of the part rect of the pixmap, or of all of it if rect is empty.

void QPixmap::fill(const QColor &color = Qt::white)

Fills the pixmap with color.

[static] QPixmap QPixmap::fromImage(const QImage &image)

Returns a pixmap with the pixels of image.

See also toImage().

bool QPixmap::hasAlphaChannel() const

Returns true if the pixmap has an alpha channel; pixmaps made by Nt do.

bool QPixmap::isNull() const

Returns true if the pixmap has no pixels.

bool QPixmap::load(const QString &fileName, const char *format = nullptr)

Loads the image file fileName and returns true if it succeeded; otherwise returns false and leaves the pixmap null. The format is ignored, as in QImage::load().

See also QImage::load() and save().

bool QPixmap::loadFromData(const uchar *data, uint len, const char *format = nullptr)

Loads the pixmap from the len bytes at data and returns true if it succeeded. The format is ignored.

See also QImage::loadFromData().

bool QPixmap::loadFromData(QByteArrayView data, const char *format = nullptr)

This is an overloaded function.

Loads the pixmap from data.

[override, protected] int QPixmap::metric(PaintDeviceMetric metric) const

Reimplements QPaintDevice::metric().

QPixmap & QPixmap::operator=(const QPixmap &other)

Makes the pixmap share the data of other and returns it.

QPixmap & QPixmap::operator=(QPixmap &&other)

Makes the pixmap take the data of other and returns it.

[override] QPaintEngine * QPixmap::paintEngine() const

Reimplements QPaintDevice::paintEngine().

QRect QPixmap::rect() const

Returns the rectangle of the pixmap, at the origin.

[override, protected] QPaintDevice * QPixmap::redirected(QPoint *offset) const

Reimplements QPaintDevice::redirected().

A painter paints on the image of the pixmap, which is detached from the copies first.

bool QPixmap::save(const QString &fileName, const char *format = nullptr, int quality = -1) const

Saves the pixmap to the file fileName and returns true if it succeeded. See QImage::save() for the format and the quality.

bool QPixmap::save(QIODevice *device, const char *format = nullptr, int quality = -1) const

This is an overloaded function.

Writes the pixmap to device, which must be open for writing.

QSize QPixmap::size() const

Returns the size of the pixmap.

void QPixmap::swap(QPixmap &other)

Swaps the pixmap with other.

QImage QPixmap::toImage() const

Returns the pixmap as an image.

See also fromImage().