Logo Search packages:      
Sourcecode: qt4-x11 version File versions

QPixmap Class Reference

Inheritance diagram for QPixmap:

QPaintDevice Q3CanvasPixmap QBitmap

List of all members.

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. And because QPixmap is a QPaintDevice subclass, QPainter can be used to draw directly onto pixmaps.

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, in it.

Note that the pixel data in a pixmap is internal and is managed by the underlying window system. Pixels can only be accessed through QPainter functions or by converting the QPixmap to a QImage. 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 and Mac, 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).

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.

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.

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.

Definition at line 45 of file qpixmap.h.

Public Types

enum  PaintDeviceMetric {
  PdmWidth = 1, PdmHeight, PdmWidthMM, PdmHeightMM,
  PdmNumColors, PdmDepth, PdmDpiX, PdmDpiY,
  PdmPhysicalDpiX, PdmPhysicalDpiY

Public Member Functions

QPixmap alphaChannel () const
QPixmap copy (const QRect &rect=QRect()) const
QPixmap copy (int x, int y, int width, int height) const
QBitmap createHeuristicMask (bool clipTight=true) const
QBitmap createMaskFromColor (const QColor &maskColor) const
int depth () const
void detach ()
int devType () const
void fill (const QWidget *widget, int xofs, int yofs)
void fill (const QWidget *widget, const QPoint &ofs)
void fill (const QColor &fillColor=Qt::white)
bool hasAlpha () const
bool hasAlphaChannel () const
int height () const
int heightMM () const
bool isDetached () const
bool isNull () const
bool isQBitmap () const
bool load (const QString &fileName, const char *format=0, Qt::ImageConversionFlags flags=Qt::AutoColor)
bool loadFromData (const QByteArray &data, const char *format=0, Qt::ImageConversionFlags flags=Qt::AutoColor)
bool loadFromData (const uchar *buf, uint len, const char *format=0, Qt::ImageConversionFlags flags=Qt::AutoColor)
int logicalDpiX () const
int logicalDpiY () const
QBitmap mask () const
int numColors () const
 operator QVariant () const
bool operator! () const
QPixmapoperator= (const QPixmap &)
QPaintEnginepaintEngine () const
bool paintingActive () const
int physicalDpiX () const
int physicalDpiY () const
 QPixmap (const QPixmap &)
 QPixmap (const char *const xpm[])
 QPixmap (const QString &fileName, const char *format=0, Qt::ImageConversionFlags flags=Qt::AutoColor)
 QPixmap (const QSize &)
 QPixmap (int w, int h)
 QPixmap ()
QRect rect () const
bool save (QIODevice *device, const char *format=0, int quality=-1) const
bool save (const QString &fileName, const char *format=0, int quality=-1) const
QPixmap scaled (const QSize &s, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
QPixmap scaled (int w, int h, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
QPixmap scaledToHeight (int h, Qt::TransformationMode mode=Qt::FastTransformation) const
QPixmap scaledToWidth (int w, Qt::TransformationMode mode=Qt::FastTransformation) const
int serialNumber () const
void setAlphaChannel (const QPixmap &)
void setMask (const QBitmap &)
QSize size () const
QImage toImage () const
QPixmap transformed (const QMatrix &, Qt::TransformationMode mode=Qt::FastTransformation) const
int width () const
int widthMM () const
 ~QPixmap ()

Static Public Member Functions

static int defaultDepth ()
static QPixmap fromImage (const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
static QPixmap grabWidget (QWidget *widget, int x=0, int y=0, int w=-1, int h=-1)
static QPixmap grabWidget (QWidget *widget, const QRect &rect)
static QPixmap grabWindow (WId, int x=0, int y=0, int w=-1, int h=-1)
static QMatrix trueMatrix (const QMatrix &m, int w, int h)

Protected Member Functions

int metric (PaintDeviceMetric) const

Protected Attributes

ushort painters

Private Types

enum  Type { PixmapType, BitmapType }

Private Member Functions

void deref ()
bool doImageIO (QImageWriter *io, int quality) const
void init (int, int, Type=PixmapType)
 QPixmap (const QSize &s, Type)

Private Attributes

QPixmapData * data


Q_GUI_EXPORT QDataStreamoperator>> (QDataStream &, QPixmap &)
class QBitmap
class QCoreGraphicsPaintEngine
class QGLWidget
class QPaintDevice
class QPainter
struct QPixmapData
class QRasterBuffer
class QRasterPaintEngine
Q_GUI_EXPORT qint64 qt_pixmap_id (const QPixmap &pixmap)
class QWidgetPrivate
class QX11PaintEngine

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &stream, const QPixmap &pixmap)
const Q_GUI_EXPORT QX11Infoqt_x11Info (const QPaintDevice *pd)

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index