QPixmap Class Reference

The QPixmap class is an off-screen image representation that can be used as a paint device.

  1. #include <QPixmap>

Inherits: QPaintDevice.

Inherited by: Q3CanvasPixmap and QBitmap.

Detailed Description

The QPixmap class is an off-screen image representation that can be used as a paint device.

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 isQBitmap() function returns true if a QPixmap object is really a bitmap, otherwise returns false. Finally, the QPicture class is a paint device that records and replays QPainter commands.

A QPixmap can easily be displayed on the screen using QLabel or one of QAbstractButton's subclasses (such as QPushButton and QToolButton). QLabel has a pixmap property, whereas QAbstractButton has an icon property.

In addition to the ordinary constructors, a QPixmap can be constructed using the static grabWidget() and grabWindow() functions which creates a QPixmap and paints the given widget, or window, into it.

QPixmap objects can be passed around by value since the QPixmap class uses implicit data sharing. For more information, see the Implicit Data Sharing documentation. QPixmap objects can also be streamed.

Depending on the system, QPixmap is stored using a RGB32 or a premultiplied alpha format. If the image has an alpha channel, and if the system allows, the preferred format is premultiplied alpha. Note also that QPixmap, unlike QImage, may be hardware dependent. On X11, Mac and Symbian, a QPixmap is stored on the server side while a QImage is stored on the client side (on Windows, these two classes have an equivalent internal representation, i.e. both QImage and QPixmap are stored on the client side and don't use any GDI resources).

Note that the pixel data in a pixmap is internal and is managed by the underlying window system. Because QPixmap is a QPaintDevice subclass, QPainter can be used to draw directly onto pixmaps. Pixels can only be accessed through QPainter functions or by converting the QPixmap to a QImage. However, the fill() function is available for initializing the entire pixmap with a given color.

There are functions to convert between QImage and QPixmap. Typically, the QImage class is used to load an image file, optionally manipulating the image data, before the QImage object is converted into a QPixmap to be shown on screen. Alternatively, if no manipulation is desired, the image file can be loaded directly into a QPixmap. On Windows, the QPixmap class also supports conversion between HBITMAP and QPixmap. On Symbian, the QPixmap class also supports conversion between CFbsBitmap and QPixmap.

QPixmap provides a collection of functions that can be used to obtain a variety of information about the pixmap. In addition, there are several functions that enables transformation of the pixmap.

Reading and Writing Image Files

QPixmap provides several ways of reading an image file: The file can be loaded when constructing the QPixmap object, or by using the load() or loadFromData() functions later on. When loading an image, the file name can either refer to an actual file on disk or to one of the application's embedded resources. See The Qt Resource System overview for details on how to embed images and other resource files in the application's executable.

Simply call the save() function to save a QPixmap object.

The complete list of supported file formats are available through the QImageReader::supportedImageFormats() and QImageWriter::supportedImageFormats() functions. New file formats can be added as plugins. By default, Qt supports the following formats:

FormatDescriptionQt's support
BMPWindows BitmapRead/write
GIFGraphic Interchange Format (optional)Read
JPGJoint Photographic Experts GroupRead/write
JPEGJoint Photographic Experts GroupRead/write
PNGPortable Network GraphicsRead/write
PBMPortable BitmapRead
PGMPortable GraymapRead
PPMPortable PixmapRead/write
XBMX11 BitmapRead/write
XPMX11 PixmapRead/write

Pixmap Information

QPixmap provides a collection of functions that can be used to obtain a variety of information about the pixmap:

Available Functions
GeometryThe size(), width() and height() functions provide information about the pixmap's size. The rect() function returns the image's enclosing rectangle.
Alpha componentThe hasAlphaChannel() returns true if the pixmap has a format that respects the alpha channel, otherwise returns false. The hasAlpha(), setMask() and mask() functions are legacy and should not be used. They are potentially very slow.

The createHeuristicMask() function creates and returns a 1-bpp heuristic mask (i.e. a QBitmap) for this pixmap. It works by selecting a color from one of the corners and then chipping away pixels of that color, starting at all the edges. The createMaskFromColor() function creates and returns a mask (i.e. a QBitmap) for the pixmap based on a given color.

Low-level informationThe depth() function returns the depth of the pixmap. The defaultDepth() function returns the default depth, i.e. the depth used by the application on the given screen.

The cacheKey() function returns a number that uniquely identifies the contents of the QPixmap object.

The x11Info() function returns information about the configuration of the X display used by the screen to which the pixmap currently belongs. The x11PictureHandle() function returns the X11 Picture handle of the pixmap for XRender support. Note that the two latter functions are only available on x11.

Pixmap Conversion

A QPixmap object can be converted into a QImage using the toImage() function. Likewise, a QImage can be converted into a QPixmap using the fromImage(). If this is too expensive an operation, you can use QBitmap::fromImage() instead.

In addition, on Windows, the QPixmap class supports conversion to and from HBITMAP: the toWinHBITMAP() function creates a HBITMAP equivalent to the QPixmap, based on the given HBitmapFormat, and returns the HBITMAP handle. The fromWinHBITMAP() function returns a QPixmap that is equivalent to the given bitmap which has the specified format. The QPixmap class also supports conversion to and from HICON: the toWinHICON() function creates a HICON equivalent to the QPixmap, and returns the HICON handle. The fromWinHICON() function returns a QPixmap that is equivalent to the given icon.

In addition, on Symbian, the QPixmap class supports conversion to and from CFbsBitmap: the toSymbianCFbsBitmap() function creates CFbsBitmap equivalent to the QPixmap, based on given mode and returns a CFbsBitmap object. The fromSymbianCFbsBitmap() function returns a QPixmap that is equivalent to the given bitmap and given mode.

Pixmap Transformations

QPixmap supports a number of functions for creating a new pixmap that is a transformed version of the original:

The scaled(), scaledToWidth() and scaledToHeight() functions return scaled copies of the pixmap, while the copy() function creates a QPixmap that is a plain copy of the original one.

The transformed() function returns a copy of the pixmap that is transformed with the given transformation matrix and transformation mode: Internally, the transformation matrix is adjusted to compensate for unwanted translation, i.e. transformed() returns the smallest pixmap containing all transformed points of the original pixmap. The static trueMatrix() function returns the actual matrix used for transforming the pixmap.

Note: When using the native X11 graphics system, the pixmap becomes invalid when the QApplication instance is destroyed.

See also QBitmap, QImage, QImageReader, and QImageWriter.

Public Types

Toggle detailsenum QPixmap::

HBitmapFormatHBitmapFormat { NoAlpha , PremultipliedAlpha , Alpha 2 ...} { NoAlpha , PremultipliedAlpha , Alpha 2 }

Win32 only: This enum defines how the conversion between HBITMAP and QPixmap is performed.

Warning: This enum is only available on Windows.

ConstantValueDescription
QPixmap::NoAlpha 0 The alpha channel is ignored and always treated as being set to fully opaque. This is preferred if the HBITMAP is used with standard GDI calls, such as BitBlt().
QPixmap::PremultipliedAlpha 1 The HBITMAP is treated as having an alpha channel and premultiplied colors. This is preferred if the HBITMAP is accessed through the AlphaBlend() GDI function.
QPixmap::Alpha 2 The HBITMAP is treated as having a plain alpha channel. This is the preferred format if the HBITMAP is going to be used as an application icon or systray icon.

See also fromWinHBITMAP() and toWinHBITMAP().

Look up this member in the source code.

Toggle detailsenum QPixmap::

ShareModeShareMode { ImplicitlyShared , ExplicitlyShared 1 ...} { ImplicitlyShared , ExplicitlyShared 1 }

This enum type defines the share modes that are available when creating a QPixmap object from a raw X11 Pixmap handle.

ConstantValueDescription
QPixmap::ImplicitlyShared 0 This mode will cause the QPixmap object to create a copy of the internal data before it is modified, thus keeping the original X11 pixmap intact.
QPixmap::ExplicitlyShared 1 In this mode, the pixmap data will not be copied before it is modified, which in effect will change the original X11 pixmap.

Warning: This enum is only used for X11 specific functions; using it is non-portable.

See also QPixmap::fromX11Pixmap().

Look up this member in the source code.

Toggle detailsenum QPixmap::

ColorModeColorMode { Auto , Color , Mono 2 ...} { Auto , Color , Mono 2 }Qt3-support

This enum type defines the color modes that exist for converting QImage objects to QPixmap. It is provided here for compatibility with earlier versions of Qt.

Use Qt::ImageConversionFlags instead.

ConstantValueDescription
QPixmap::Auto 0 Select Color or Mono on a case-by-case basis.
QPixmap::Color 1 Always create colored pixmaps.
QPixmap::Mono 2 Always create bitmaps.

Look up this member in the source code.

Public Functions

Toggle details QPixmap

QPixmapQPixmap () ()

Constructs a null pixmap.

See also isNull().

Look up this member in the source code.

Toggle details QPixmap

QPixmapQPixmap ( int width , int height ) ( int width , int height )

Constructs a pixmap with the given width and height. If either width or height is zero, a null pixmap is constructed.

Warning: This will create a QPixmap with uninitialized data. Call fill() to fill the pixmap with an appropriate color before drawing onto it with QPainter.

See also isNull().

Look up this member in the source code.

Toggle details QPixmap

QPixmapQPixmap ( const QString &fileName , const char *format=0 , Qt::ImageConversionFlags flags=Qt::AutoColor ...) ( const QString &fileName , const char *format=0 , Qt::ImageConversionFlags flags=Qt::AutoColor )

Constructs a pixmap from the file with the given fileName. If the file does not exist or is of an unknown format, the pixmap becomes a null pixmap.

The loader attempts to read the pixmap using the specified format. If the format is not specified (which is the default), the loader probes the file for a header to guess the file format.

The file name can either refer to an actual file on disk or to one of the application's embedded resources. See the Resource System overview for details on how to embed images and other resource files in the application's executable.

If the image needs to be modified to fit in a lower-resolution result (e.g. converting from 32-bit to 8-bit), use the flags to control the conversion.

The fileName, format and flags parameters are passed on to load(). This means that the data in fileName is not compiled into the binary. If fileName contains a relative path (e.g. the filename only) the relevant file must be found relative to the runtime working directory.

See also Reading and Writing Image Files.

Look up this member in the source code.

Toggle details QPixmap

QPixmapQPixmap ( const char * const[]xpm ) ( const char * const[]xpm )

Constructs a pixmap from the given xpm data, which must be a valid XPM image.

Errors are silently ignored.

Note that it's possible to squeeze the XPM variable a little bit by using an unusual declaration:

  1. static const char * const start_xpm[]= {
  2.     "16 15 8 1",
  3.     "a c #cec6bd",
  4. ....

The extra const makes the entire definition read-only, which is slightly more efficient (for example, when the code is in a shared library) and ROMable when the application is to be stored in ROM.

Look up this member in the source code.

Toggle details QPixmap

QPixmapQPixmap ( const QPixmap &pixmap ) ( const QPixmap &pixmap )

Constructs a pixmap that is a copy of the given pixmap.

See also copy().

Look up this member in the source code.

Toggle details QPixmap

QPixmapQPixmap ( const QSize &size ) ( const QSize &size )

This is an overloaded function.

Constructs a pixmap of the given size.

Warning: This will create a QPixmap with uninitialized data. Call fill() to fill the pixmap with an appropriate color before drawing onto it with QPainter.

Look up this member in the source code.

Toggle details QPixmap

~QPixmap~QPixmap () ()

Destroys the pixmap.

Look up this member in the source code.

Toggle details qint64 QPixmap

cacheKeycacheKey () ()const

Returns a number that identifies this QPixmap. Distinct QPixmap objects can only have the same cache key if they refer to the same contents.

The cacheKey() will change when the pixmap is altered.

Look up this member in the source code.

Toggle details bool QPixmap

convertFromImageconvertFromImage ( const QImage &image , Qt::ImageConversionFlags flags=Qt::AutoColor ...) ( const QImage &image , Qt::ImageConversionFlags flags=Qt::AutoColor )

Replaces this pixmap's data with the given image using the specified flags to control the conversion. The flags argument is a bitwise-OR of the Qt::ImageConversionFlags. Passing 0 for flags sets all the default options. Returns true if the result is that this pixmap is not null.

Note: this function was part of Qt 3 support in Qt 4.6 and earlier. It has been promoted to official API status in 4.7 to support updating the pixmap's image without creating a new QPixmap as fromImage() would.

See also fromImage().

Look up this member in the source code.

Toggle details QPixmap QPixmap

copycopy ( const QRect &rectangle=QRect() ) ( const QRect &rectangle=QRect() )const

Returns a deep copy of the subset of the pixmap that is specified by the given rectangle. For more information on deep copies, see the Implicit Data Sharing documentation.

If the given rectangle is empty, the whole image is copied.

See also operator=(), QPixmap(), and Pixmap Transformations.

Look up this member in the source code.

Toggle details QPixmap QPixmap

copycopy ( int x , int y , int width , int height ) ( int x , int y , int width , int height )const

This is an overloaded function.

Returns a deep copy of the subset of the pixmap that is specified by the rectangle QRect( x, y, width, height).

Look up this member in the source code.

Toggle details QBitmap QPixmap

createHeuristicMaskcreateHeuristicMask ( bool clipTight=true ( bool clipTight=true )const

Creates and returns a heuristic mask for this pixmap.

The function works by selecting a color from one of the corners and then chipping away pixels of that color, starting at all the edges. If clipTight is true (the default) the mask is just large enough to cover the pixels; otherwise, the mask is larger than the data pixels.

The mask may not be perfect but it should be reasonable, so you can do things such as the following:

  1.                     QPixmap myPixmap;
  2. myPixmap->setMask(myPixmap->createHeuristicMask());

This function is slow because it involves converting to/from a QImage, and non-trivial computations.

See also QImage::createHeuristicMask() and createMaskFromColor().

Look up this member in the source code.

Toggle details QBitmap QPixmap

createMaskFromColorcreateMaskFromColor ( const QColor &maskColor , Qt::MaskMode mode ...) ( const QColor &maskColor , Qt::MaskMode mode )const

Creates and returns a mask for this pixmap based on the given maskColor. If the mode is Qt::MaskInColor, all pixels matching the maskColor will be transparent. If mode is Qt::MaskOutColor, all pixels matching the maskColor will be opaque.

This function is slow because it involves converting to/from a QImage.

See also createHeuristicMask() and QImage::createMaskFromColor().

Look up this member in the source code.

Toggle details QBitmap QPixmap

createMaskFromColorcreateMaskFromColor ( const QColor &maskColor ...) ( const QColor &maskColor )const

This is an overloaded function.

Creates and returns a mask for this pixmap based on the given maskColor. Same as calling createMaskFromColor(maskColor, Qt::MaskInColor)

See also createHeuristicMask() and QImage::createMaskFromColor().

Look up this member in the source code.

Toggle details int QPixmap

defaultDepthdefaultDepth () () [static]

Returns the default pixmap depth used by the application.

On Windows and Mac, the default depth is always 32. On X11 and embedded, the depth of the screen will be returned by this function.

See also depth(), QColormap::depth(), and Pixmap Information.

Look up this member in the source code.

Toggle details int QPixmap

depthdepth () ()const

Returns the depth of the pixmap.

The pixmap depth is also called bits per pixel (bpp) or bit planes of a pixmap. A null pixmap has depth 0.

See also defaultDepth() and Pixmap Information.

Look up this member in the source code.

Toggle details void QPixmap

detachdetach () ()

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.

There are two exceptions in which detach() must be called explicitly, that is when calling the handle() or the x11PictureHandle() function (only available on X11). Otherwise, any modifications done using system calls, will be performed on the shared data.

The detach() function returns immediately if there is just a single reference or if the pixmap has not been initialized yet.

Look up this member in the source code.

Toggle details void QPixmap

fillfill ( const QColor &color=Qt::white ) ( const QColor &color=Qt::white )

Fills the pixmap with the given color.

The effect of this function is undefined when the pixmap is being painted on.

See also Pixmap Transformations.

Look up this member in the source code.

Toggle details void QPixmap

fillfill ( const QWidget *widget , const QPoint &offset ...) ( const QWidget *widget , const QPoint &offset )

Fills the pixmap with the widget's background color or pixmap according to the given offset.

The QPoint offset defines a point in widget coordinates to which the pixmap's top-left pixel will be mapped to. This is only significant if the widget has a background pixmap; otherwise the pixmap will simply be filled with the background color of the widget.

Look up this member in the source code.

Toggle details void QPixmap

fillfill ( const QWidget *widget , int x , int y ) ( const QWidget *widget , int x , int y )

This is an overloaded function.

Fills the pixmap with the widget's background color or pixmap. The given point, (x, y), defines an offset in widget coordinates to which the pixmap's top-left pixel will be mapped to.

Look up this member in the source code.

Toggle details QPixmap QPixmap

fromImagefromImage ( const QImage &image , Qt::ImageConversionFlags flags=Qt::AutoColor ...) ( const QImage &image , Qt::ImageConversionFlags flags=Qt::AutoColor ) [static]

Converts the given image to a pixmap using the specified flags to control the conversion. The flags argument is a bitwise-OR of the Qt::ImageConversionFlags. Passing 0 for flags sets all the default options.

In case of monochrome and 8-bit images, the image is first converted to a 32-bit pixmap and then filled with the colors in the color table. If this is too expensive an operation, you can use QBitmap::fromImage() instead.

See also fromImageReader(), toImage(), and Pixmap Conversion.

Look up this member in the source code.

Toggle details QPixmap QPixmap

fromImageReaderfromImageReader ( QImageReader *imageReader , Qt::ImageConversionFlags flags=Qt::AutoColor ...) ( QImageReader *imageReader , Qt::ImageConversionFlags flags=Qt::AutoColor ) [static]

Create a QPixmap from an image read directly from an imageReader. The flags argument is a bitwise-OR of the Qt::ImageConversionFlags. Passing 0 for flags sets all the default options.

On some systems, reading an image directly to QPixmap can use less memory than reading a QImage to convert it to QPixmap.

See also fromImage(), toImage(), and Pixmap Conversion.

Look up this member in the source code.

Toggle details QPixmap QPixmap

fromMacCGImageReffromMacCGImageRef ( CGImageRefimage ) ( CGImageRefimage ) [static]

Returns a QPixmap that is equivalent to the given image.

Warning: This function is only available on Mac OS X.

See also toMacCGImageRef() and Pixmap Conversion.

Look up this member in the source code.

Toggle details QPixmap QPixmap

fromSymbianCFbsBitmapfromSymbianCFbsBitmap ( CFbsBitmap *bitmap ) ( CFbsBitmap *bitmap ) [static]

Creates a QPixmap from a CFbsBitmap bitmap. Internally this function will try to duplicate the bitmap handle instead of copying the data, however in scenarios where this is not possible the data will be copied. To be sure that QPixmap does not modify your original instance, you should make a copy of your CFbsBitmap before calling this function. If the CFbsBitmap is not valid this function will return a null QPixmap. For performance reasons it is recommended to use a bitmap with a display mode of EColor16MAP or EColor16MU whenever possible.

Warning: This function is only available on Symbian OS.

See also toSymbianCFbsBitmap() and Pixmap Conversion.

Look up this member in the source code.

Toggle details QPixmap QPixmap

fromSymbianRSgImagefromSymbianRSgImage ( RSgImage *sgImage ) ( RSgImage *sgImage ) [static]

Returns a QPixmap that wraps given sgImage graphics resource. The data should be valid even when original RSgImage handle has been closed.

Warning: This function is only available on Symbian OS.

See also toSymbianRSgImage() and Pixmap Conversion.

Look up this member in the source code.

Toggle details QPixmap QPixmap

fromWinHBITMAPfromWinHBITMAP ( HBITMAPbitmap , HBitmapFormat format=NoAlpha ...) ( HBITMAPbitmap , HBitmapFormat format=NoAlpha ) [static]

Win32 only: Returns a QPixmap that is equivalent to the given bitmap. The conversion is based on the specified format.

Warning: This function is only available on Windows.

See also toWinHBITMAP() and Pixmap Conversion.

Look up this member in the source code.

Toggle details QPixmap QPixmap

fromWinHICONfromWinHICON ( HICONicon ) ( HICONicon ) [static]

Win32 only: Returns a QPixmap that is equivalent to the given icon.

Warning: This function is only available on Windows.

See also toWinHICON() and Pixmap Conversion.

Look up this member in the source code.

Toggle details QPixmap QPixmap

fromX11PixmapfromX11Pixmap ( Qt::HANDLE pixmap , ShareMode mode=ImplicitlyShared ...) ( Qt::HANDLE pixmap , ShareMode mode=ImplicitlyShared ) [static]

Creates a QPixmap from the native X11 Pixmap handle pixmap, using mode as the share mode. The default share mode is QPixmap::ImplicitlyShared, which means that a copy of the pixmap is made if someone tries to modify it by e.g. drawing onto it.

QPixmap does not take ownership of the pixmap handle, and have to be deleted by the user.

Warning: This function is X11 specific; using it is non-portable.

See also QPixmap::ShareMode.

Look up this member in the source code.

Toggle details QPixmap QPixmap

grabWidgetgrabWidget ( QWidget *widget , const QRect &rectangle ...) ( QWidget *widget , const QRect &rectangle ) [static]

Creates a pixmap and paints the given widget, restricted by the given rectangle, in it. If the widget has any children, then they are also painted in the appropriate positions.

If no rectangle is specified (the default) the entire widget is painted.

If widget is 0, the specified rectangle doesn't overlap the widget's rectangle, or an error occurs, the function will return a null QPixmap. If the rectangle is a superset of the given widget, the areas outside the widget are covered with the widget's background.

This function actually asks widget to paint itself (and its children to paint themselves) by calling paintEvent() with painter redirection turned on. But QPixmap also provides the grabWindow() function which is a bit faster by grabbing pixels directly off the screen. In addition, if there are overlaying windows, grabWindow(), unlike grabWidget(), will see them.

Warning: Do not grab a widget from its QWidget::paintEvent(). However, it is safe to grab a widget from another widget's paintEvent().

See also grabWindow().

Look up this member in the source code.

Toggle details QPixmap QPixmap

grabWidgetgrabWidget ( QWidget *widget , int x=0 , int y=0 , int width=-1 , int height=-1 ...) ( QWidget *widget , int x=0 , int y=0 , int width=-1 , int height=-1 ) [static]

This is an overloaded function.

Creates a pixmap and paints the given widget, restricted by QRect(x, y, width, height), in it.

Warning: Do not grab a widget from its QWidget::paintEvent(). However, it is safe to grab a widget from another widget's paintEvent().

Look up this member in the source code.

Toggle details QPixmap QPixmap

grabWindowgrabWindow ( WId window , int x=0 , int y=0 , int width=-1 , int height=-1 ...) ( WId window , int x=0 , int y=0 , int width=-1 , int height=-1 ) [static]

Creates and returns a pixmap constructed by grabbing the contents of the given window restricted by QRect(x, y, width, height).

The arguments (x, y) specify the offset in the window, whereas (width, height) specify the area to be copied. If width is negative, the function copies everything to the right border of the window. If height is negative, the function copies everything to the bottom of the window.

The window system identifier (WId) can be retrieved using the QWidget::winId() function. The rationale for using a window identifier and not a QWidget, is to enable grabbing of windows that are not part of the application, window system frames, and so on.

The grabWindow() function grabs pixels from the screen, not from the window, i.e. if there is another window partially or entirely over the one you grab, you get pixels from the overlying window, too. The mouse cursor is generally not grabbed.

Note on X11 that if the given window doesn't have the same depth as the root window, and another window partially or entirely obscures the one you grab, you will not get pixels from the overlying window. The contents of the obscured areas in the pixmap will be undefined and uninitialized.

On Windows Vista and above grabbing a layered window, which is created by setting the Qt::WA_TranslucentBackground attribute, will not work. Instead grabbing the desktop widget should work.

Warning: In general, grabbing an area outside the screen is not safe. This depends on the underlying window system.

See also grabWidget() and Screenshot Example.

Look up this member in the source code.

Toggle details Qt::HANDLE QPixmap

handlehandle () ()const

Returns the pixmap's handle to the device context.

Note that, since QPixmap make use of implicit data sharing, the detach() function must be called explicitly to ensure that only this pixmap's data is modified if the pixmap data is shared.

Warning: This function is X11 specific; using it is non-portable.

See also detach().

Look up this member in the source code.

Toggle details bool QPixmap

hasAlphahasAlpha () ()const

Returns true if this pixmap has an alpha channel, or has a mask, otherwise returns false.

See also hasAlphaChannel() and mask().

Look up this member in the source code.

Toggle details bool QPixmap

hasAlphaChannelhasAlphaChannel () ()const

Returns true if the pixmap has a format that respects the alpha channel, otherwise returns false.

See also hasAlpha().

Look up this member in the source code.

Toggle details int QPixmap

heightheight () ()const

Returns the height of the pixmap.

See also size() and Pixmap Information.

Look up this member in the source code.

Toggle details bool QPixmap

isNullisNull () ()const

Returns true if this is a null pixmap; otherwise returns false.

A null pixmap has zero width, zero height and no contents. You cannot draw in a null pixmap.

Look up this member in the source code.

Toggle details bool QPixmap

isQBitmapisQBitmap () ()const

Returns true if this is a QBitmap; otherwise returns false.

Look up this member in the source code.

Toggle details bool QPixmap

loadload ( const QString &fileName , const char *format=0 , Qt::ImageConversionFlags flags=Qt::AutoColor ...) ( const QString &fileName , const char *format=0 , Qt::ImageConversionFlags flags=Qt::AutoColor )

Loads a pixmap from the file with the given fileName. Returns true if the pixmap was successfully loaded; otherwise returns false.

The loader attempts to read the pixmap using the specified format. If the format is not specified (which is the default), the loader probes the file for a header to guess the file format.

The file name can either refer to an actual file on disk or to one of the application's embedded resources. See the Resource System overview for details on how to embed pixmaps and other resource files in the application's executable.

If the data needs to be modified to fit in a lower-resolution result (e.g. converting from 32-bit to 8-bit), use the flags to control the conversion.

Note that QPixmaps are automatically added to the QPixmapCache when loaded from a file; the key used is internal and can not be acquired.

See also loadFromData() and Reading and Writing Image Files.

Look up this member in the source code.

Toggle details bool QPixmap

loadFromDataloadFromData ( const uchar *data , uint len , const char *format=0 , Qt::ImageConversionFlags flags=Qt::AutoColor ...) ( const uchar *data , uint len , const char *format=0 , Qt::ImageConversionFlags flags=Qt::AutoColor )

Loads a pixmap from the len first bytes of the given binary data. Returns true if the pixmap was loaded successfully; otherwise returns false.

The loader attempts to read the pixmap using the specified format. If the format is not specified (which is the default), the loader probes the file for a header to guess the file format.

If the data needs to be modified to fit in a lower-resolution result (e.g. converting from 32-bit to 8-bit), use the flags to control the conversion.

See also load() and Reading and Writing Image Files.

Look up this member in the source code.

Toggle details bool QPixmap

loadFromDataloadFromData ( const QByteArray &data , const char *format=0 , Qt::ImageConversionFlags flags=Qt::AutoColor ...) ( const QByteArray &data , const char *format=0 , Qt::ImageConversionFlags flags=Qt::AutoColor )

This is an overloaded function.

Loads a pixmap from the binary data using the specified format and conversion flags.

Look up this member in the source code.

Toggle details QBitmap QPixmap

maskmask () ()const

Extracts a bitmap mask from the pixmap's alpha channel.

Warning: This is potentially an expensive operation. The mask of the pixmap is extracted dynamically from the pixeldata.

See also setMask() and Pixmap Information.

Look up this member in the source code.

Toggle details QRect QPixmap

rectrect () ()const

Returns the pixmap's enclosing rectangle.

See also Pixmap Information.

Look up this member in the source code.

Toggle details bool QPixmap

savesave ( const QString &fileName , const char *format=0 , int quality=-1 ...) ( const QString &fileName , const char *format=0 , int quality=-1 )const

Saves the pixmap to the file with the given fileName using the specified image file format and quality factor. Returns true if successful; otherwise returns false.

The quality factor must be in the range [0,100] or -1. Specify 0 to obtain small compressed files, 100 for large uncompressed files, and -1 to use the default settings.

If format is 0, an image format will be chosen from fileName's suffix.

See also Reading and Writing Image Files.

Look up this member in the source code.

Toggle details bool QPixmap

savesave ( QIODevice *device , const char *format=0 , int quality=-1 ...) ( QIODevice *device , const char *format=0 , int quality=-1 )const

This is an overloaded function.

This function writes a QPixmap to the given device using the specified image file format and quality factor. This can be used, for example, to save a pixmap directly into a QByteArray:

  1.         QPixmap pixmap;
  2.         QByteArray bytes;
  3.         QBuffer buffer(&bytes);
  4.         buffer.open(QIODevice::WriteOnly);
  5.         pixmap.save(&buffer, "PNG"); // writes pixmap into bytes in PNG format

Look up this member in the source code.

Toggle details QPixmap QPixmap

scaledscaled ( const QSize &size , Qt::AspectRatioMode aspectRatioMode=Qt::IgnoreAspectRatio , Qt::TransformationMode transformMode=Qt::FastTransformation ...) ( const QSize &size , Qt::AspectRatioMode aspectRatioMode=Qt::IgnoreAspectRatio , Qt::TransformationMode transformMode=Qt::FastTransformation )const

Scales the pixmap to the given size, using the aspect ratio and transformation modes specified by aspectRatioMode and transformMode.

  • If aspectRatioMode is Qt::IgnoreAspectRatio, the pixmap is scaled to size.
  • If aspectRatioMode is Qt::KeepAspectRatio, the pixmap is scaled to a rectangle as large as possible inside size, preserving the aspect ratio.
  • If aspectRatioMode is Qt::KeepAspectRatioByExpanding, the pixmap is scaled to a rectangle as small as possible outside size, preserving the aspect ratio.

If the given size is empty, this function returns a null pixmap.

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.

Look up this member in the source code.

Toggle details QPixmap QPixmap

scaledscaled ( int width , int height , Qt::AspectRatioMode aspectRatioMode=Qt::IgnoreAspectRatio , Qt::TransformationMode transformMode=Qt::FastTransformation ...) ( int width , int height , Qt::AspectRatioMode aspectRatioMode=Qt::IgnoreAspectRatio , Qt::TransformationMode transformMode=Qt::FastTransformation )const

This is an overloaded function.

Returns a copy of the pixmap scaled to a rectangle with the given width and height according to the given aspectRatioMode and transformMode.

If either the width or the height is zero or negative, this function returns a null pixmap.

Look up this member in the source code.

Toggle details QPixmap QPixmap

scaledToHeightscaledToHeight ( int height , Qt::TransformationMode mode=Qt::FastTransformation ...) ( int height , Qt::TransformationMode mode=Qt::FastTransformation )const

Returns a scaled copy of the image. The returned image is scaled to the given height using the specified transformation mode. The width of the pixmap is automatically calculated so that the aspect ratio of the pixmap is preserved.

If height is 0 or negative, a null pixmap is returned.

See also isNull() and Pixmap Transformations.

Look up this member in the source code.

Toggle details QPixmap QPixmap

scaledToWidthscaledToWidth ( int width , Qt::TransformationMode mode=Qt::FastTransformation ...) ( int width , Qt::TransformationMode mode=Qt::FastTransformation )const

Returns a scaled copy of the image. The returned image is scaled to the given width using the specified transformation mode. The height of the pixmap is automatically calculated so that the aspect ratio of the pixmap is preserved.

If width is 0 or negative, a null pixmap is returned.

See also isNull() and Pixmap Transformations.

Look up this member in the source code.

Toggle details void QPixmap

scrollscroll ( int dx , int dy , int x , int y , int width , int height , QRegion *exposed=0 ...) ( int dx , int dy , int x , int y , int width , int height , QRegion *exposed=0 )

This convenience function is equivalent to calling QPixmap::scroll(dx, dy, QRect(x, y, width, height), exposed).

See also QWidget::scroll() and QGraphicsItem::scroll().

Look up this member in the source code.

Toggle details void QPixmap

scrollscroll ( int dx , int dy , const QRect &rect , QRegion *exposed=0 ...) ( int dx , int dy , const QRect &rect , QRegion *exposed=0 )

Scrolls the area rect of this pixmap by (dx, dy). The exposed region is left unchanged. You can optionally pass a pointer to an empty QRegion to get the region that is exposed by the scroll operation.

  1.                     QPixmap pixmap("background.png");
  2. QRegion exposed;
  3. pixmap.scroll(10, 10, pixmap.rect(), &exposed);

You cannot scroll while there is an active painter on the pixmap.

See also QWidget::scroll() and QGraphicsItem::scroll().

Look up this member in the source code.

Toggle details void QPixmap

setMasksetMask ( const QBitmap &mask ) ( const QBitmap &mask )

Sets a mask bitmap.

This function merges the mask with the pixmap's alpha channel. A pixel value of 1 on the mask means the pixmap's pixel is unchanged; a value of 0 means the pixel is transparent. The mask must have the same size as this pixmap.

Setting a null mask resets the mask, leaving the previously transparent pixels black. The effect of this function is undefined when the pixmap is being painted on.

Warning: This is potentially an expensive operation.

See also mask(), Pixmap Transformations, and QBitmap.

Look up this member in the source code.

Toggle details QSize QPixmap

sizesize () ()const

Returns the size of the pixmap.

See also width(), height(), and Pixmap Information.

Look up this member in the source code.

Toggle details QImage QPixmap

toImagetoImage () ()const

Converts the pixmap to a QImage. Returns a null image if the conversion fails.

If the pixmap has 1-bit depth, the returned image will also be 1 bit deep. Images with more bits will be returned in a format closely represents the underlying system. Usually this will be QImage::Format_ARGB32_Premultiplied for pixmaps with an alpha and QImage::Format_RGB32 or QImage::Format_RGB16 for pixmaps without alpha.

Note that for the moment, alpha masks on monochrome images are ignored.

See also fromImage() and Image Formats.

Look up this member in the source code.

Toggle details CGImageRef QPixmap

toMacCGImageReftoMacCGImageRef () ()const

Creates a CGImageRef equivalent to the QPixmap. Returns the CGImageRef handle.

It is the caller's responsibility to release the CGImageRef data after use.

Warning: This function is only available on Mac OS X.

See also fromMacCGImageRef().

Look up this member in the source code.

Toggle details CFbsBitmap * QPixmap

toSymbianCFbsBitmaptoSymbianCFbsBitmap () ()const

Creates a CFbsBitmap that is equivalent to the QPixmap. Internally this function will try to duplicate the handle instead of copying the data, however in scenarios where this is not possible the data will be copied. If the creation fails or the pixmap is null, then this function returns 0.

It is the caller's responsibility to release the CFbsBitmap data after use either by deleting the bitmap or calling Reset().

Warning: On S60 3.1 and S60 3.2, semi-transparent pixmaps are always copied and not duplicated.

Warning: This function is only available on Symbian OS.

See also fromSymbianCFbsBitmap().

Look up this member in the source code.

Toggle details RSgImage * QPixmap

toSymbianRSgImagetoSymbianRSgImage () ()const

Returns a RSgImage that is equivalent to the QPixmap by copying the data.

It is the caller's responsibility to close/delete the RSgImage after use.

Warning: This function is only available on Symbian OS.

See also fromSymbianRSgImage().

Look up this member in the source code.

Toggle details HBITMAP QPixmap

toWinHBITMAPtoWinHBITMAP ( HBitmapFormat format=NoAlpha ...) ( HBitmapFormat format=NoAlpha )const

Win32 only: Creates a HBITMAP equivalent to the QPixmap, based on the given format. Returns the HBITMAP handle.

It is the caller's responsibility to free the HBITMAP data after use.

Warning: This function is only available on Windows.

See also fromWinHBITMAP() and Pixmap Conversion.

Look up this member in the source code.

Toggle details HICON QPixmap

toWinHICONtoWinHICON () ()const

Win32 only: Creates a HICON equivalent to the QPixmap. Returns the HICON handle.

It is the caller's responsibility to free the HICON data after use.

Warning: This function is only available on Windows.

See also fromWinHICON() and Pixmap Conversion.

Look up this member in the source code.

Toggle details QPixmap QPixmap

transformedtransformed ( const QTransform &transform , Qt::TransformationMode mode=Qt::FastTransformation ...) ( const QTransform &transform , Qt::TransformationMode mode=Qt::FastTransformation )const

Returns a copy of the pixmap that is transformed using the given transformation transform and transformation mode. The original pixmap is not changed.

The transformation transform is internally adjusted to compensate for unwanted translation; i.e. the pixmap produced is the smallest pixmap that contains all the transformed points of the original pixmap. Use the trueMatrix() function to retrieve the actual matrix used for transforming the pixmap.

This function is slow because it involves transformation to a QImage, non-trivial computations and a transformation back to a QPixmap.

See also trueMatrix() and Pixmap Transformations.

Look up this member in the source code.

Toggle details QPixmap QPixmap

transformedtransformed ( const QMatrix &matrix , Qt::TransformationMode mode=Qt::FastTransformation ...) ( const QMatrix &matrix , Qt::TransformationMode mode=Qt::FastTransformation )const

This is an overloaded function.

This convenience function loads the matrix into a QTransform and calls the overloaded function.

Look up this member in the source code.

Toggle details QTransform QPixmap

trueMatrixtrueMatrix ( const QTransform &matrix , int width , int height ...) ( const QTransform &matrix , int width , int height ) [static]

Returns the actual matrix used for transforming a pixmap with the given width, height and matrix.

When transforming a pixmap using the transformed() function, the transformation matrix is internally adjusted to compensate for unwanted translation, i.e. transformed() returns the smallest pixmap containing all transformed points of the original pixmap. This function returns the modified matrix, which maps points correctly from the original pixmap into the new pixmap.

See also transformed() and Pixmap Transformations.

Look up this member in the source code.

Toggle details QMatrix QPixmap

trueMatrixtrueMatrix ( const QMatrix &m , int w , int h ( const QMatrix &m , int w , int h ) [static]

This is an overloaded function.

This convenience function loads the matrix m into a QTransform and calls the overloaded function with the QTransform and the width w and the height h.

Look up this member in the source code.

Toggle details int QPixmap

widthwidth () ()const

Returns the width of the pixmap.

See also size() and Pixmap Information.

Look up this member in the source code.

Toggle details const QX11Info & QPixmap

x11Infox11Info () ()const

X11 only: Returns information about the configuration of the X display used by the screen to which the pixmap currently belongs.

Warning: This function is only available on X11.

See also Pixmap Information.

Look up this member in the source code.

Toggle details Qt::HANDLE QPixmap

x11PictureHandlex11PictureHandle () ()const

X11 only: Returns the X11 Picture handle of the pixmap for XRender support.

This function will return 0 if XRender support is not compiled into Qt, if the XRender extension is not supported on the X11 display, or if the handle could not be created. Use of this function is not portable.

Warning: This function is only available on X11.

See also Pixmap Information.

Look up this member in the source code.

Toggle details QPixmap

operator QVariantoperator QVariant () ()const

Returns the pixmap as a QVariant.

Look up this member in the source code.

Toggle details bool QPixmap

operator!operator! () ()const

Returns true if this is a null pixmap; otherwise returns false.

See also isNull().

Look up this member in the source code.

Toggle details QPixmap & QPixmap

operator=operator= ( const QPixmap &pixmap ) ( const QPixmap &pixmap )

Assigns the given pixmap to this pixmap and returns a reference to this pixmap.

See also copy() and QPixmap().

Look up this member in the source code.

Toggle details QPixmap QPixmap

alphaChannelalphaChannel () ()const Obsolete function

Returns the alpha channel of the pixmap as a new grayscale QPixmap in which each pixel's red, green, and blue values are given the alpha value of the original pixmap. The color depth of the returned pixmap is the system depth on X11 and 8-bit on Windows and Mac OS X.

You can use this function while debugging to get a visible image of the alpha channel. If the pixmap doesn't have an alpha channel, i.e., the alpha channel's value for all pixels equals 0xff), a null pixmap is returned. You can check this with the isNull() function.

We show an example:

  1.         pixmap = QPixmap(100, 100);
  2.         pixmap.fill(Qt::transparent);
  3.  
  4.         QRadialGradient gradient(50, 50, 50, 50, 50);
  5.         gradient.setColorAt(0, QColor::fromRgbF(1, 0, 0, 1));
  6.         gradient.setColorAt(1, QColor::fromRgbF(0, 0, 0, 0));
  7.         QPainter painter(&pixmap);
  8.         painter.fillRect(0, 0, 100, 100, gradient);
  9.  
  10.         channelImage = pixmap.alphaChannel();
  11.         update();
The pixmap and channelImage QPixmaps

The pixmap and channelImage QPixmaps

Warning: This is an expensive operation. The alpha channel of the pixmap is extracted dynamically from the pixeldata. Most usecases of this function are covered by QPainter and compositionModes which will normally execute faster.

See also setAlphaChannel() and Pixmap Information.

Look up this member in the source code.

Toggle details int QPixmap

serialNumberserialNumber () ()const Obsolete function

Returns a number that identifies the contents of this QPixmap object. Distinct QPixmap objects can only have the same serial number if they refer to the same contents (but they don't have to).

Use cacheKey() instead.

Warning: The serial number doesn't necessarily change when the pixmap is altered. This means that it may be dangerous to use it as a cache key. For caching pixmaps, we recommend using the QPixmapCache class whenever possible.

Look up this member in the source code.

Toggle details void QPixmap

setAlphaChannelsetAlphaChannel ( const QPixmap &alphaChannel ) ( const QPixmap &alphaChannel ) Obsolete function

Sets the alpha channel of this pixmap to the given alphaChannel by converting the alphaChannel into 32 bit and using the intensity of the RGB pixel values.

The effect of this function is undefined when the pixmap is being painted on.

Warning: This is potentially an expensive operation. Most usecases for this function are covered by QPainter and compositionModes which will normally execute faster.

See also alphaChannel() and Pixmap Transformations.

Look up this member in the source code.

Toggle details QPixmap

QPixmapQPixmap ( const QString &fileName , const char *format , ColorMode mode ...) ( const QString &fileName , const char *format , ColorMode mode ) Qt3-support

Use the constructor that takes a Qt::ImageConversionFlag instead.

Look up this member in the source code.

Toggle details QPixmap

QPixmapQPixmap ( const QImage &image ) ( const QImage &image ) Qt3-support

Constructs a pixmap from the QImage image.

Use the static fromImage() function instead.

Look up this member in the source code.

Toggle details bool QPixmap

convertFromImageconvertFromImage ( const QImage &image , ColorMode mode ...) ( const QImage &image , ColorMode mode ) Qt3-support

Use the static fromImage() function instead.

Look up this member in the source code.

Toggle details QImage QPixmap

convertToImageconvertToImage () ()const Qt3-support

Use the toImage() function instead.

Look up this member in the source code.

Toggle details bool QPixmap

loadload ( const QString &fileName , const char *format , ColorMode mode ...) ( const QString &fileName , const char *format , ColorMode mode ) Qt3-support

Use the load() function that takes a Qt::ImageConversionFlag instead.

Look up this member in the source code.

Toggle details bool QPixmap

loadFromDataloadFromData ( const uchar *buf , uint len , const char *format , ColorMode mode ...) ( const uchar *buf , uint len , const char *format , ColorMode mode ) Qt3-support

Use the loadFromData() function that takes a Qt::ImageConversionFlag instead.

Look up this member in the source code.

Toggle details void QPixmap

resizeresize ( int width , int height ) ( int width , int height ) Qt3-support

Use QPixmap::copy() instead to get the pixmap with the new size.

For example, if you have code like

  1. pixmap.resize(10, 20);

you can rewrite it as

  1. pixmap = pixmap.copy(0, 0, 10, 20);

Look up this member in the source code.

Toggle details void QPixmap

resizeresize ( const QSize &size ) ( const QSize &size ) Qt3-support

This is an overloaded function.

Use QPixmap::copy() instead to get the pixmap with the new size.

For example, if you have code like

  1. pixmap.resize(size);

you can rewrite it as

  1. pixmap = pixmap.copy(QRect(QPoint(0, 0), size));

Look up this member in the source code.

Toggle details bool QPixmap

selfMaskselfMask () ()const Qt3-support

Returns whether the pixmap is its own mask or not.

This function is no longer relevant since the concept of self masking doesn't exists anymore.

Look up this member in the source code.

Toggle details QPixmap QPixmap

xFormxForm ( const QMatrix &matrix ) ( const QMatrix &matrix )const Qt3-support

Use transformed() instead.

Look up this member in the source code.

Toggle details QPixmap

operator QImageoperator QImage () ()const Qt3-support

Returns the pixmap as a QImage.

Use the toImage() function instead.

Look up this member in the source code.

Toggle details QPixmap & QPixmap

operator=operator= ( const QImage &image ) ( const QImage &image ) Qt3-support

This is an overloaded function.

Converts the given image to a pixmap that is assigned to this pixmap.

Use the static fromImage() function instead.

Look up this member in the source code.

Notes provided by the Qt Community
Informative
  • 0

Votes: 0

Coverage: Qt library 4.7, 4.8, 5.0

Picture of Rahul Das Rahul Das

Robot Herder
7 notes

Tips for Symbian Developers

QPixmap is found to handle images of limited sizes. For Huge images QPixmap::scaled returns Null QPixmap on Symbian.

Using QImageReader for such operations is recommended.

[Revisions]