Qt 4.8
Public Types | Public Functions | Static Public Functions | Protected Functions | Private Types | Private Functions | Properties | Friends | Related Functions | List of all members
QPixmap Class Reference

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

#include <qpixmap.h>

Inheritance diagram for QPixmap:
QPaintDevice QBitmap QPixmapCacheEntry

Public Types

typedef QExplicitlySharedDataPointer< QPixmapDataDataPtr
 
enum  HBitmapFormat { NoAlpha, PremultipliedAlpha, Alpha }
 HBITMAP and QPixmap is performed. More...
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric {
  PdmWidth = 1, PdmHeight, PdmWidthMM, PdmHeightMM,
  PdmNumColors, PdmDepth, PdmDpiX, PdmDpiY,
  PdmPhysicalDpiX, PdmPhysicalDpiY
}
 

Public Functions

QT_DEPRECATED QPixmap alphaChannel () const
 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. More...
 
qint64 cacheKey () const
 Returns a number that identifies this QPixmap. More...
 
QRgbclut () const
 
int colorCount () const
 
bool convertFromImage (const QImage &img, Qt::ImageConversionFlags flags=Qt::AutoColor)
 Replaces this pixmap's data with the given image using the specified flags to control the conversion. More...
 
QPixmap copy (int x, int y, int width, int height) const
 Returns a deep copy of the subset of the pixmap that is specified by the rectangle QRect( x, y, width, height). More...
 
QPixmap copy (const QRect &rect=QRect()) const
 Returns a deep copy of the subset of the pixmap that is specified by the given rectangle. More...
 
QBitmap createHeuristicMask (bool clipTight=true) const
 Creates and returns a heuristic mask for this pixmap. More...
 
QBitmap createMaskFromColor (const QColor &maskColor) const
 Creates and returns a mask for this pixmap based on the given maskColor. More...
 
QBitmap createMaskFromColor (const QColor &maskColor, Qt::MaskMode mode) const
 Creates and returns a mask for this pixmap based on the given maskColor. More...
 
DataPtrdata_ptr ()
 
int depth () const
 Returns the depth of the pixmap. More...
 
void detach ()
 Detaches the pixmap from shared pixmap data. More...
 
int devType () const
 
void fill (const QColor &fillColor=Qt::white)
 Fills the pixmap with the given color. More...
 
void fill (const QWidget *widget, const QPoint &ofs)
 Fills the pixmap with the widget's background color or pixmap according to the given offset. More...
 
void fill (const QWidget *widget, int xofs, int yofs)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Fills the pixmap with the widget's background color or pixmap. More...
 
Qt::HANDLE handle () const
 Returns the pixmap's handle to the device context. More...
 
bool hasAlpha () const
 Returns true if this pixmap has an alpha channel, or has a mask, otherwise returns false. More...
 
bool hasAlphaChannel () const
 Returns true if the pixmap has a format that respects the alpha channel, otherwise returns false. More...
 
int height () const
 Returns the height of the pixmap. More...
 
bool isDetached () const
 
bool isNull () const
 Returns true if this is a null pixmap; otherwise returns false. More...
 
bool isQBitmap () const
 Returns true if this is a QBitmap; otherwise returns false. More...
 
bool load (const QString &fileName, const char *format=0, Qt::ImageConversionFlags flags=Qt::AutoColor)
 Loads a pixmap from the file with the given fileName. More...
 
bool loadFromData (const uchar *buf, uint len, const char *format=0, Qt::ImageConversionFlags flags=Qt::AutoColor)
 Loads a pixmap from the len first bytes of the given binary data. More...
 
bool loadFromData (const QByteArray &data, const char *format=0, Qt::ImageConversionFlags flags=Qt::AutoColor)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Loads a pixmap from the binary data using the specified format and conversion flags. More...
 
QBitmap mask () const
 Extracts a bitmap mask from the pixmap's alpha channel. More...
 
QT_DEPRECATED int numCols () const
 
 operator QVariant () const
 Returns the pixmap as a QVariant. More...
 
bool operator! () const
 Returns true if this is a null pixmap; otherwise returns false. More...
 
QPixmapoperator= (const QPixmap &)
 Assigns the given pixmap to this pixmap and returns a reference to this pixmap. More...
 
QPaintEnginepaintEngine () const
 
QPixmapDatapixmapData () const
 
 QPixmap ()
 Constructs a null pixmap. More...
 
 QPixmap (QPixmapData *data)
 
 QPixmap (int w, int h)
 Constructs a pixmap with the given width and height. More...
 
 QPixmap (const QSize &)
 Constructs a pixmap of the given size. More...
 
 QPixmap (const QString &fileName, const char *format=0, Qt::ImageConversionFlags flags=Qt::AutoColor)
 Constructs a pixmap from the file with the given fileName. More...
 
 QPixmap (const char *const xpm[])
 Constructs a pixmap from the given xpm data, which must be a valid XPM image. More...
 
 QPixmap (const QPixmap &)
 Constructs a pixmap that is a copy of the given pixmap. More...
 
const ucharqwsBits () const
 
int qwsBytesPerLine () const
 
QRect rect () const
 Returns the pixmap's enclosing rectangle. More...
 
bool save (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. More...
 
bool save (QIODevice *device, const char *format=0, int quality=-1) const
 This function writes a QPixmap to the given device using the specified image file format and quality factor. More...
 
QPixmap scaled (int w, int h, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
 
QPixmap scaled (const QSize &s, 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
 Returns a scaled copy of the image. More...
 
void scroll (int dx, int dy, int x, int y, int width, int height, QRegion *exposed=0)
 
void scroll (int dx, int dy, const QRect &rect, QRegion *exposed=0)
 Scrolls the area rect of this pixmap by (dx, dy). More...
 
QT_DEPRECATED int serialNumber () const
 Returns a number that identifies the contents of this QPixmap object. More...
 
QT_DEPRECATED void setAlphaChannel (const QPixmap &)
 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. More...
 
void setMask (const QBitmap &)
 Sets a mask bitmap. More...
 
QSize size () const
 Returns the size of the pixmap. More...
 
void swap (QPixmap &other)
 Swaps pixmap other with this pixmap. More...
 
QImage toImage () const
 Converts the pixmap to a QImage. More...
 
CGImageRef toMacCGImageRef () const
 Creates a CGImageRef equivalent to the QPixmap. More...
 
HBITMAP toWinHBITMAP (HBitmapFormat format=NoAlpha) const
 It is the caller's responsibility to free the HBITMAP data after use. More...
 
HICON toWinHICON () const
 Returns the HICON handle. More...
 
QPixmap transformed (const QMatrix &, Qt::TransformationMode mode=Qt::FastTransformation) const
 This convenience function loads the matrix into a QTransform and calls the overloaded function. More...
 
QPixmap transformed (const QTransform &, Qt::TransformationMode mode=Qt::FastTransformation) const
 Returns a copy of the pixmap that is transformed using the given transformation transform and transformation mode. More...
 
int width () const
 Returns the width of the pixmap. More...
 
 ~QPixmap ()
 Destroys the pixmap. More...
 
- Public Functions inherited from QPaintDevice
int colorCount () const
 
int depth () const
 
virtual HDC getDC () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
QT_DEPRECATED int numColors () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
virtual void releaseDC (HDC hdc) const
 
int width () const
 
int widthMM () const
 
virtual ~QPaintDevice ()
 

Static Public Functions

static int defaultDepth ()
 Returns the default pixmap depth used by the application. More...
 
static QPixmap fromImage (const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
 Converts the given image to a pixmap using the specified flags to control the conversion. More...
 
static QPixmap fromImageReader (QImageReader *imageReader, Qt::ImageConversionFlags flags=Qt::AutoColor)
 Create a QPixmap from an image read directly from an imageReader. More...
 
static QPixmap fromMacCGImageRef (CGImageRef image)
 Returns a QPixmap that is equivalent to the given image. More...
 
static QPixmap fromWinHBITMAP (HBITMAP hbitmap, HBitmapFormat format=NoAlpha)
 Win32 only: Returns a QPixmap that is equivalent to the given bitmap. More...
 
static QPixmap fromWinHICON (HICON hicon)
 
static QPixmap grabWidget (QWidget *widget, const QRect &rect)
 Creates a pixmap and paints the given widget, restricted by the given rectangle, in it. More...
 
static QPixmap grabWidget (QWidget *widget, int x=0, int y=0, int w=-1, int h=-1)
 
static QPixmap grabWindow (WId, int x=0, int y=0, int w=-1, int h=-1)
 Creates and returns a pixmap constructed by grabbing the contents of the given window restricted by QRect(x, y, width, height). More...
 
static QMatrix trueMatrix (const QMatrix &m, int w, int h)
 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. More...
 
static QTransform trueMatrix (const QTransform &m, int w, int h)
 Returns the actual matrix used for transforming a pixmap with the given width, height and matrix. More...
 
- Static Public Functions inherited from QPaintDevice
static QWSDisplayqwsDisplay ()
 

Protected Functions

int metric (PaintDeviceMetric) const
 
- Protected Functions inherited from QPaintDevice
 QPaintDevice ()
 

Private Types

enum  Type { PixmapType, BitmapType }
 

Private Functions

void deref ()
 
bool doImageIO (QImageWriter *io, int quality) const
 
void init (int, int, Type=PixmapType)
 
void init (int, int, int)
 
void initAlphaPixmap (uchar *bytes, int length, struct tagBITMAPINFO *bmi)
 
 QPixmap (const QSize &s, Type)
 
 QPixmap (const QSize &s, int type)
 

Properties

QExplicitlySharedDataPointer< QPixmapDatadata
 

Friends

Q_GUI_EXPORT QDataStreamoperator>> (QDataStream &, QPixmap &)
 Reads an image from the given stream into the given pixmap. More...
 
class QBitmap
 
class QCoreGraphicsPaintEngine
 
class QGLWidget
 
class QMacPixmapData
 
class QPaintDevice
 
class QPainter
 
class QPixmapData
 
class QRasterBuffer
 
class QSymbianRasterPixmapData
 
CGContextRef qt_mac_cg_context (const QPaintDevice *)
 Returns the CoreGraphics CGContextRef of the paint device. More...
 
IconRef qt_mac_create_iconref (const QPixmap &)
 
CGImageRef qt_mac_create_imagemask (const QPixmap &, const QRectF &)
 
quint32qt_mac_pixmap_get_base (const QPixmap *)
 
int qt_mac_pixmap_get_bytes_per_line (const QPixmap *)
 
Q_GUI_EXPORT qint64 qt_pixmap_id (const QPixmap &pixmap)
 
class QWidgetPrivate
 
class QX11PaintEngine
 
class QX11PixmapData
 

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &stream, const QPixmap &pixmap)
 Writes the given pixmap to the given stream as a PNG image. More...
 

Additional Inherited Members

- Protected Variables inherited from QPaintDevice
ushort painters
 

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.

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:

Format Description Qt's support
BMP Windows Bitmap Read/write
GIF Graphic Interchange Format (optional) Read
JPG Joint Photographic Experts Group Read/write
JPEG Joint Photographic Experts Group Read/write
PNG Portable Network Graphics Read/write
PBM Portable Bitmap Read
PGM Portable Graymap Read
PPM Portable Pixmap Read/write
XBM X11 Bitmap Read/write
XPM X11 Pixmap Read/write

Pixmap Information

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

Available Functions
Geometry

The size(), width() and height() functions provide information about the pixmap's size. The rect() function returns the image's enclosing rectangle.

Alpha component

The 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 information

The 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, QImageWriter

Definition at line 71 of file qpixmap.h.

Typedefs

◆ DataPtr

Warning
This function is not part of the public interface.

Definition at line 296 of file qpixmap.h.

Enumerations

◆ HBitmapFormat

HBITMAP and QPixmap is performed.

Win32 only: This enum defines how the conversion between

Warning
This enum is only available on Windows.
  • NoAlpha 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().
  • PremultipliedAlpha 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.
  • Alpha 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(), toWinHBITMAP()
Enumerator
NoAlpha 
PremultipliedAlpha 
Alpha 

Definition at line 157 of file qpixmap.h.

◆ Type

enum QPixmap::Type
private
Enumerator
PixmapType 
BitmapType 

Definition at line 257 of file qpixmap.h.

257 { PixmapType, BitmapType }; // must match QPixmapData::PixelType

Constructors and Destructors

◆ QPixmap() [1/9]

QPixmap::QPixmap ( )

Constructs a null pixmap.

See also
isNull()

Definition at line 174 of file qpixmap.cpp.

Referenced by alphaChannel(), copy(), depth(), QBitmap::fromImage(), fromImage(), fromImageReader(), fromWinHBITMAP(), fromWinHICON(), grabWidget(), handle(), scaled(), scaledToHeight(), scaledToWidth(), and toWinHBITMAP().

175  : QPaintDevice()
176 {
177  (void) qt_pixmap_thread_test();
179 }
void init(int, int, Type=PixmapType)
Definition: qpixmap.cpp:128
static bool qt_pixmap_thread_test()
Definition: qpixmap.cpp:99

◆ QPixmap() [2/9]

QPixmap::QPixmap ( QPixmapData d)
explicit
Warning
This function is not part of the public interface.

Definition at line 254 of file qpixmap.cpp.

255  : QPaintDevice(), data(d)
256 {
257 }
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252

◆ QPixmap() [3/9]

QPixmap::QPixmap ( 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()

Definition at line 198 of file qpixmap.cpp.

199  : QPaintDevice()
200 {
201  if (!qt_pixmap_thread_test())
203  else
205 }
void init(int, int, Type=PixmapType)
Definition: qpixmap.cpp:128
static bool qt_pixmap_thread_test()
Definition: qpixmap.cpp:99

◆ QPixmap() [4/9]

QPixmap::QPixmap ( const QSize size)

Constructs a pixmap of the given size.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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.

Definition at line 220 of file qpixmap.cpp.

221  : QPaintDevice()
222 {
223  if (!qt_pixmap_thread_test())
225  else
226  init(size.width(), size.height(), QPixmapData::PixmapType);
227 }
void init(int, int, Type=PixmapType)
Definition: qpixmap.cpp:128
static bool qt_pixmap_thread_test()
Definition: qpixmap.cpp:99
int width() const
Returns the width.
Definition: qsize.h:126
int height() const
Returns the height.
Definition: qsize.h:129

◆ QPixmap() [5/9]

QPixmap::QPixmap ( 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
{QPixmap::Reading and Writing Image Files}{Reading and Writing Image Files}

Definition at line 287 of file qpixmap.cpp.

288  : QPaintDevice()
289 {
291  if (!qt_pixmap_thread_test())
292  return;
293 
294  load(fileName, format, flags);
295 }
void init(int, int, Type=PixmapType)
Definition: qpixmap.cpp:128
bool load(const QString &fileName, const char *format=0, Qt::ImageConversionFlags flags=Qt::AutoColor)
Loads a pixmap from the file with the given fileName.
Definition: qpixmap.cpp:930
static bool qt_pixmap_thread_test()
Definition: qpixmap.cpp:99

◆ QPixmap() [6/9]

QPixmap::QPixmap ( 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:

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

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.

Definition at line 333 of file qpixmap.cpp.

334  : QPaintDevice()
335 {
337  if (!xpm)
338  return;
339 
340  QImage image(xpm);
341  if (!image.isNull()) {
343  *this = QBitmap::fromImage(image);
344  else
345  *this = fromImage(image);
346  }
347 }
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition: qpixmap.cpp:2197
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
void init(int, int, Type=PixmapType)
Definition: qpixmap.cpp:128
PixelType pixelType() const
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static QBitmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Returns a copy of the given image converted to a bitmap using the specified image conversion flags...
Definition: qbitmap.cpp:281

◆ QPixmap() [7/9]

QPixmap::QPixmap ( const QPixmap pixmap)

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

See also
copy()

Definition at line 303 of file qpixmap.cpp.

304  : QPaintDevice()
305 {
306  if (!qt_pixmap_thread_test()) {
308  return;
309  }
310  if (pixmap.paintingActive()) { // make a deep copy
311  operator=(pixmap.copy());
312  } else {
313  data = pixmap.data;
314  }
315 }
QPixmap & operator=(const QPixmap &)
Assigns the given pixmap to this pixmap and returns a reference to this pixmap.
Definition: qpixmap.cpp:471
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
void init(int, int, Type=PixmapType)
Definition: qpixmap.cpp:128
bool paintingActive() const
Definition: qpaintdevice.h:170
static bool qt_pixmap_thread_test()
Definition: qpixmap.cpp:99
QPixmap copy(int x, int y, int width, int height) const
Returns a deep copy of the subset of the pixmap that is specified by the rectangle QRect( x...
Definition: qpixmap.h:302

◆ ~QPixmap()

QPixmap::~QPixmap ( )

Destroys the pixmap.

Definition at line 355 of file qpixmap.cpp.

356 {
357  Q_ASSERT(!data || data->ref >= 1); // Catch if ref-counting changes again
358 }
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QAtomicInt ref

◆ QPixmap() [8/9]

QPixmap::QPixmap ( const QSize s,
Type  type 
)
private
Warning
This function is not part of the public interface.

Definition at line 232 of file qpixmap.cpp.

233 {
234  if (!qt_pixmap_thread_test())
235  init(0, 0, type);
236  else
237  init(s.width(), s.height(), type);
238 }
int type
Definition: qmetatype.cpp:239
void init(int, int, Type=PixmapType)
Definition: qpixmap.cpp:128
static bool qt_pixmap_thread_test()
Definition: qpixmap.cpp:99
int width() const
Returns the width.
Definition: qsize.h:126
int height() const
Returns the height.
Definition: qsize.h:129

◆ QPixmap() [9/9]

QPixmap::QPixmap ( const QSize s,
int  type 
)
private
Warning
This function is not part of the public interface.

Definition at line 243 of file qpixmap.cpp.

244 {
245  if (!qt_pixmap_thread_test())
246  init(0, 0, static_cast<QPixmapData::PixelType>(type));
247  else
248  init(s.width(), s.height(), static_cast<QPixmapData::PixelType>(type));
249 }
int type
Definition: qmetatype.cpp:239
void init(int, int, Type=PixmapType)
Definition: qpixmap.cpp:128
static bool qt_pixmap_thread_test()
Definition: qpixmap.cpp:99
int width() const
Returns the width.
Definition: qsize.h:126
int height() const
Returns the height.
Definition: qsize.h:129

Functions

◆ alphaChannel()

QPixmap QPixmap::alphaChannel ( ) const

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:

pixmap = QPixmap(100, 100);
pixmap.fill(Qt::transparent);
QRadialGradient gradient(50, 50, 50, 50, 50);
gradient.setColorAt(0, QColor::fromRgbF(1, 0, 0, 1));
gradient.setColorAt(1, QColor::fromRgbF(0, 0, 0, 0));
QPainter painter(&pixmap);
painter.fillRect(0, 0, 100, 100, gradient);
channelImage = pixmap.alphaChannel();
update();
alphachannelimage.png
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(), {QPixmap::Pixmap Information}{Pixmap Information}

Definition at line 2051 of file qpixmap.cpp.

2052 {
2053  return data ? data->alphaChannel() : QPixmap();
2054 }
QPixmap()
Constructs a null pixmap.
Definition: qpixmap.cpp:174
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
virtual QPixmap alphaChannel() const

◆ cacheKey()

qint64 QPixmap::cacheKey ( ) 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.

Definition at line 1136 of file qpixmap.cpp.

Referenced by QPdfEngine::drawPixmap(), QTextHtmlExporter::emitBackgroundAttribute(), QGLBlurTextureCache::insertBlurTextureInfo(), operator<<(), QBrush::operator==(), QPixmapIconEngine::pixmap(), qBrushDark(), qBrushLight(), qBrushSetAlphaF(), qDrawPlainRect(), qt_mac_fill_background(), qt_pixmap_id(), QLabel::setPixmap(), and QGLBlurTextureCache::takeBlurTextureInfo().

1137 {
1138  if (isNull())
1139  return 0;
1140 
1141  Q_ASSERT(data);
1142  return data->cacheKey();
1143 }
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
qint64 cacheKey() const

◆ clut()

QRgb * QPixmap::clut ( ) const
Warning
This function is not part of the public interface.

Definition at line 115 of file qpixmap_qws.cpp.

116 {
117  if (data && data->classId() == QPixmapData::RasterClass) {
118  const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data());
119  return d->image.colorTable().data();
120  }
121 
122  return 0;
123 }
double d
Definition: qnumeric_p.h:62
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
ClassId classId() const
T * data()
Returns a pointer to the data stored in the vector.
Definition: qvector.h:152
QVector< QRgb > colorTable() const
Returns a list of the colors contained in the image&#39;s color table, or an empty list if the image does...
Definition: qimage.cpp:1770

◆ colorCount()

int QPixmap::colorCount ( ) const
Since
4.6
Warning
This function is not part of the public interface.

Definition at line 130 of file qpixmap_qws.cpp.

Referenced by numCols().

131 {
132  if (data && data->classId() == QPixmapData::RasterClass) {
133  const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data());
134  return d->image.colorCount();
135  }
136 
137  return 0;
138 }
double d
Definition: qnumeric_p.h:62
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
ClassId classId() const
int colorCount() const
Returns the size of the color table for the image.
Definition: qimage.cpp:1656

◆ convertFromImage()

bool QPixmap::convertFromImage ( 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()
Since
4.7

Definition at line 1531 of file qpixmap.cpp.

Referenced by handle().

1532 {
1533  if (image.isNull() || !data)
1534  *this = QPixmap::fromImage(image, flags);
1535  else
1536  data->fromImage(image, flags);
1537  return !isNull();
1538 }
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition: qpixmap.cpp:2197
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
virtual void fromImage(const QImage &image, Qt::ImageConversionFlags flags)=0
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615

◆ copy() [1/2]

QPixmap QPixmap::copy ( int  x,
int  y,
int  width,
int  height 
) const
inline

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 302 of file qpixmap.h.

Referenced by detach(), QPixmapBlurFilter::draw(), QPixmapColorizeFilter::draw(), QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(), QPSPrintEngine::drawPixmap(), QWin32PrintEngine::drawPixmap(), QPdfEngine::drawPixmap(), QPainter::drawPixmap(), QOpenGLPaintEngine::drawTiledPixmap(), operator=(), QPixmap(), scaledToHeight(), and scaledToWidth().

303 {
304  return copy(QRect(ax, ay, awidth, aheight));
305 }
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QPixmap copy(int x, int y, int width, int height) const
Returns a deep copy of the subset of the pixmap that is specified by the rectangle QRect( x...
Definition: qpixmap.h:302

◆ copy() [2/2]

QPixmap QPixmap::copy ( 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(), {QPixmap::Pixmap Transformations}{Pixmap Transformations}

Definition at line 394 of file qpixmap.cpp.

395 {
396  if (isNull())
397  return QPixmap();
398 
399  QRect r(0, 0, width(), height());
400  if (!rect.isEmpty())
401  r = r.intersected(rect);
402 
404  d->copy(data.data(), r);
405  return QPixmap(d);
406 }
virtual QPixmapData * createCompatiblePixmapData() const
Definition: qpixmapdata.cpp:96
double d
Definition: qnumeric_p.h:62
QPixmap()
Constructs a null pixmap.
Definition: qpixmap.cpp:174
int width() const
Returns the width of the pixmap.
Definition: qpixmap.cpp:630
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
virtual void copy(const QPixmapData *data, const QRect &rect)
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QRect rect() const
Returns the pixmap&#39;s enclosing rectangle.
Definition: qpixmap.cpp:676
int height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615

◆ createHeuristicMask()

QBitmap QPixmap::createHeuristicMask ( 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:

QPixmap myPixmap;
myPixmap->setMask(myPixmap->createHeuristicMask());

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

See also
QImage::createHeuristicMask(), createMaskFromColor()

Definition at line 864 of file qpixmap.cpp.

Referenced by isServerProcess(), qDrawPlainRect(), and QGraphicsPixmapItemPrivate::updateShape().

865 {
867  return m;
868 }
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
The QBitmap class provides monochrome (1-bit depth) pixmaps.
Definition: qbitmap.h:55
static QBitmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Returns a copy of the given image converted to a bitmap using the specified image conversion flags...
Definition: qbitmap.cpp:281
QBitmap createHeuristicMask(bool clipTight=true) const
Creates and returns a heuristic mask for this pixmap.
Definition: qpixmap.cpp:864

◆ createMaskFromColor() [1/2]

QBitmap QPixmap::createMaskFromColor ( const QColor maskColor) const

Creates and returns a mask for this pixmap based on the given maskColor.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Same as calling createMaskFromColor(maskColor, Qt::MaskInColor)

See also
createHeuristicMask(), QImage::createMaskFromColor()

Definition at line 899 of file qpixmap.cpp.

900 {
901  return createMaskFromColor(maskColor, Qt::MaskInColor);
902 }
QBitmap createMaskFromColor(const QColor &maskColor) const
Creates and returns a mask for this pixmap based on the given maskColor.
Definition: qpixmap.cpp:899

◆ createMaskFromColor() [2/2]

QBitmap QPixmap::createMaskFromColor ( 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(), QImage::createMaskFromColor()

Definition at line 882 of file qpixmap.cpp.

883 {
885  return QBitmap::fromImage(image.createMaskFromColor(maskColor.rgba(), mode));
886 }
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
static QBitmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Returns a copy of the given image converted to a bitmap using the specified image conversion flags...
Definition: qbitmap.cpp:281
QRgb rgba() const
Returns the RGB value of the color, including its alpha.
Definition: qcolor.cpp:1019
QImage createMaskFromColor(QRgb color, Qt::MaskMode mode=Qt::MaskInColor) const
Creates and returns a mask for this image based on the given color value.
Definition: qimage.cpp:4865

◆ data_ptr()

DataPtr & QPixmap::data_ptr ( )
inline

◆ defaultDepth()

int QPixmap::defaultDepth ( )
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(), {QPixmap::Pixmap Information}{Pixmap Information}

Definition at line 2092 of file qpixmap.cpp.

Referenced by QMacPixmapData::fromImage().

2093 {
2094 #if defined(Q_WS_QWS)
2095  return QScreen::instance()->depth();
2096 #elif defined(Q_WS_X11)
2097  return QX11Info::appDepth();
2098 #elif defined(Q_WS_WINCE)
2099  return QColormap::instance().depth();
2100 #elif defined(Q_WS_WIN)
2101  return 32; // XXX
2102 #elif defined(Q_WS_MAC)
2103  return 32;
2104 #elif defined(Q_OS_SYMBIAN)
2105  return S60->screenDepth;
2106 #elif defined(Q_WS_QPA)
2107  return 32; //LITE: use graphicssystem (we should do that in general)
2108 #endif
2109 }
static QColormap instance(int screen=-1)
static int appDepth(int screen=-1)
Returns the color depth (bits per pixel) used by the application on the given screen.
int depth() const
static QScreen * instance()
Returns a pointer to the application&#39;s QScreen instance.
Definition: qscreen_qws.h:201
int depth() const
Returns the depth of the framebuffer, in bits per pixel.
Definition: qscreen_qws.h:229

◆ depth()

int QPixmap::depth ( ) const

◆ deref()

void QPixmap::deref ( )
private
Warning
This function is not part of the public interface.

Qt5 - remove me.

Definition at line 1503 of file qpixmap.cpp.

1504 {
1505  Q_ASSERT_X(false, "QPixmap::deref()", "Do not call this function anymore!");
1506 }
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837

◆ detach()

void QPixmap::detach ( )

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.

Definition at line 2128 of file qpixmap.cpp.

Referenced by fill(), scroll(), setAlphaChannel(), and setMask().

2129 {
2130  if (!data)
2131  return;
2132 
2133  // QPixmap.data member may be QRuntimePixmapData so use pixmapData() function to get
2134  // the actual underlaying runtime pixmap data.
2135  QPixmapData *pd = pixmapData();
2136  QPixmapData::ClassId id = pd->classId();
2137  if (id == QPixmapData::RasterClass) {
2138  QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>(pd);
2139  rasterData->image.detach();
2140  }
2141 
2142  if (data->is_cached && data->ref == 1)
2144 
2145 #if defined(Q_WS_MAC)
2146  QMacPixmapData *macData = id == QPixmapData::MacClass ? static_cast<QMacPixmapData*>(pd) : 0;
2147  if (macData) {
2148  if (macData->cg_mask) {
2149  CGImageRelease(macData->cg_mask);
2150  macData->cg_mask = 0;
2151  }
2152  }
2153 #endif
2154 
2155  if (data->ref != 1) {
2156  *this = copy();
2157  }
2158  ++data->detach_no;
2159 
2160 #if defined(Q_WS_X11)
2161  if (pd->classId() == QPixmapData::X11Class) {
2162  QX11PixmapData *d = static_cast<QX11PixmapData*>(pd);
2164 
2165  // reset the cache data
2166  if (d->hd2) {
2167  XFreePixmap(X11->display, d->hd2);
2168  d->hd2 = 0;
2169  }
2170  }
2171 #elif defined(Q_WS_MAC)
2172  if (macData) {
2173  macData->macReleaseCGImageRef();
2174  macData->uninit = false;
2175  }
2176 #endif
2177 }
double d
Definition: qnumeric_p.h:62
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
#define X11
Definition: qt_x11_p.h:724
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
void detach()
If multiple images share common data, this image makes a copy of the data and detaches itself from th...
Definition: qimage.cpp:1359
ClassId classId() const
static void executePixmapDataModificationHooks(QPixmapData *)
QAtomicInt ref
QPixmap copy(int x, int y, int width, int height) const
Returns a deep copy of the subset of the pixmap that is specified by the rectangle QRect( x...
Definition: qpixmap.h:302
Qt::HANDLE hd2
QPixmapData * pixmapData() const
Definition: qpixmap.cpp:2277

◆ devType()

int QPixmap::devType ( ) const
virtual
Warning
This function is not part of the public interface.

Reimplemented from QPaintDevice.

Definition at line 363 of file qpixmap.cpp.

364 {
365  return QInternal::Pixmap;
366 }

◆ doImageIO()

bool QPixmap::doImageIO ( QImageWriter writer,
int  quality 
) const
private
Warning
This function is not part of the public interface.

Definition at line 1047 of file qpixmap.cpp.

Referenced by save().

1048 {
1049  if (quality > 100 || quality < -1)
1050  qWarning("QPixmap::save: quality out of range [-1,100]");
1051  if (quality >= 0)
1052  writer->setQuality(qMin(quality,100));
1053  return writer->write(toImage());
1054 }
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
void setQuality(int quality)
This is an image format specific function that sets the quality level of the image to quality...
Q_CORE_EXPORT void qWarning(const char *,...)
bool write(const QImage &image)
Writes the image image to the assigned device or file name.

◆ fill() [1/3]

void QPixmap::fill ( 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
{QPixmap::Pixmap Transformations}{Pixmap Transformations}

Definition at line 1080 of file qpixmap.cpp.

Referenced by _q_paintIntoCache(), QX11PixmapData::alphaChannel(), QBalloonTip::balloon(), QBitmap::clear(), create32BitCursor(), QOleDropSource::createCursors(), QItemDelegate::decoration(), depth(), QMacStylePrivate::drawColorlessButton(), QMacStylePrivate::drawCombobox(), QPlastiqueStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QGtkStyle::drawControl(), QMacStyle::drawControl(), QGraphicsScenePrivate::drawItemHelper(), QDeclarativeTextPrivate::drawOutline(), QOpenGLPaintEngine::drawPixmap(), QWindowsVistaStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QMacStylePrivate::drawTableHeader(), QX11PaintEngine::drawTiledPixmap(), QOpenGLPaintEngine::drawTiledPixmap(), QPaintEngine::drawTiledPixmap(), fromMacCGImageRef(), QComboMenuDelegate::getStyleOption(), grabWidget(), QStyledItemDelegate::initStyleOption(), QColorWell::mouseMoveEvent(), QColorShowLabel::mouseMoveEvent(), QDeclarativePaintedItem::paint(), QAxHostWidget::paintEvent(), QGraphicsItemEffectSourcePrivate::pixmap(), QWidgetEffectSourcePrivate::pixmap(), QMacStyle::polish(), QCursor::QCursor(), qt_mac_convert_iconref(), qt_mac_draw_pattern(), QWidgetPrivate::render_helper(), QAbstractItemViewPrivate::renderToPixmap(), QTreeViewPrivate::renderTreeToPixmapForAnimation(), QX11GLWindowSurface::setGeometry(), QTabBarPrivate::setupMovableTab(), QHeaderViewPrivate::setupSectionIndicator(), QWorkspacePrivate::showMaximizeControls(), QWindowsVistaStyle::standardIconImplementation(), QMacStyle::standardIconImplementation(), QMacStyle::styleHint(), QDeclarativeTextPrivate::textDocumentImage(), QDeclarativeTextPrivate::textLayoutImage(), toWinHICON(), QX11PixmapData::transformed(), and QCursorData::update().

1081 {
1082  if (isNull())
1083  return;
1084 
1085  // Some people are probably already calling fill while a painter is active, so to not break
1086  // their programs, only print a warning and return when the fill operation could cause a crash.
1087  if (paintingActive() && (color.alpha() != 255) && !hasAlphaChannel()) {
1088  qWarning("QPixmap::fill: Cannot fill while pixmap is being painted on");
1089  return;
1090  }
1091 
1092  if (data->ref == 1) {
1093  // detach() will also remove this pixmap from caches, so
1094  // it has to be called even when ref == 1.
1095  detach();
1096  } else {
1097  // Don't bother to make a copy of the data object, since
1098  // it will be filled with new pixel data anyway.
1100  d->resize(data->width(), data->height());
1101  data = d;
1102  }
1103  data->fill(color);
1104 }
virtual QPixmapData * createCompatiblePixmapData() const
Definition: qpixmapdata.cpp:96
double d
Definition: qnumeric_p.h:62
virtual void fill(const QColor &color)=0
void detach()
Detaches the pixmap from shared pixmap data.
Definition: qpixmap.cpp:2128
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
virtual void resize(int width, int height)=0
int width() const
bool paintingActive() const
Definition: qpaintdevice.h:170
Q_CORE_EXPORT void qWarning(const char *,...)
ushort alpha
Returns the alpha color component of this color.
Definition: qcolor.h:242
QAtomicInt ref
int height() const
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
bool hasAlphaChannel() const
Returns true if the pixmap has a format that respects the alpha channel, otherwise returns false...
Definition: qpixmap.cpp:1965

◆ fill() [2/3]

void QPixmap::fill ( 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.

Definition at line 2385 of file qwidget.cpp.

2386 {
2387  QPainter p(this);
2388  p.translate(-off);
2389  widget->d_func()->paintBackground(&p, QRect(off, size()));
2390 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ fill() [3/3]

void QPixmap::fill ( const QWidget widget,
int  x,
int  y 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.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.

Definition at line 107 of file qpixmap.h.

Referenced by fill().

107 { fill(widget, QPoint(xofs, yofs)); }
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Definition: qpixmap.cpp:1080
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53

◆ fromImage()

QPixmap QPixmap::fromImage ( 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(), {QPixmap::Pixmap Conversion}{Pixmap Conversion}

Definition at line 2197 of file qpixmap.cpp.

Referenced by QX11PixmapData::alphaChannel(), QPixmapData::alphaChannel(), QDirectFBCursor::changeCursor(), QBitmap::clear(), convert(), convertFromImage(), createPixmapDataSync(), darkenPixmap(), QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(), QMacStylePrivate::drawColorlessButton(), QWindowsVistaStyle::drawControl(), QCommonStyle::drawControl(), QWindowsStyle::drawControl(), QMotifStyle::drawControl(), QPaintEngine::drawImage(), QWindowsStyle::drawPrimitive(), QDeclarativePixmapReply::event(), fromWinHBITMAP(), fromWinHICON(), QWindowsMobileStyle::generatedIconPixmap(), QCommonStyle::generatedIconPixmap(), QMacStyle::generatedIconPixmap(), QGtkPainter::getIcon(), getPixmap(), QWindowSurface::grabWidget(), QXlibIntegration::grabWindow(), QVNCIntegration::grabWindow(), handle(), QPainterState::init(), QStyledItemDelegate::initStyleOption(), isServerProcess(), QMoviePrivate::next(), QLabel::paintEvent(), QColorLuminancePicker::paintEvent(), QSvgIconEngine::pixmap(), QTexturedBrushData::pixmap(), qBrushDark(), qBrushLight(), qBrushSetAlphaF(), QPixmap(), QAlphaWidget::render(), QGtkPainter::renderTheme(), QColorPicker::resizeEvent(), QAlphaWidget::run(), QItemDelegate::selected(), QWSServer::setBackground(), QCursor::setPos(), QCommonStyle::standardPixmap(), QWindowsMobileStyle::standardPixmap(), QMotifStyle::standardPixmap(), QGtkStyle::standardPixmap(), toWinHICON(), QX11PixmapData::transformed(), QPixmapData::transformed(), and QX11Data::xdndMimeDataForAtom().

2198 {
2199  if (image.isNull())
2200  return QPixmap();
2201 
2205  data->fromImage(image, flags);
2206  return QPixmap(data.take());
2207 }
QPixmap()
Constructs a null pixmap.
Definition: qpixmap.cpp:174
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
virtual void fromImage(const QImage &image, Qt::ImageConversionFlags flags)=0
virtual QPixmapData * createPixmapData(QPixmapData::PixelType type) const =0
static QGraphicsSystem * graphicsSystem()
static QPixmapData * createDefaultPixmapData(QPixmapData::PixelType type)

◆ fromImageReader()

QPixmap QPixmap::fromImageReader ( 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(), {QPixmap::Pixmap Conversion}{Pixmap Conversion}

Definition at line 2221 of file qpixmap.cpp.

2222 {
2226  data->fromImageReader(imageReader, flags);
2227  return QPixmap(data.take());
2228 }
QPixmap()
Constructs a null pixmap.
Definition: qpixmap.cpp:174
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
virtual QPixmapData * createPixmapData(QPixmapData::PixelType type) const =0
static QGraphicsSystem * graphicsSystem()
static QPixmapData * createDefaultPixmapData(QPixmapData::PixelType type)
virtual void fromImageReader(QImageReader *imageReader, Qt::ImageConversionFlags flags)

◆ fromMacCGImageRef()

QPixmap QPixmap::fromMacCGImageRef ( CGImageRef  image)
static

Returns a QPixmap that is equivalent to the given image.

Since
4.2
Warning
This function is only available on Mac OS X.
See also
toMacCGImageRef(), {QPixmap::Pixmap Conversion}{Pixmap Conversion}

Definition at line 1271 of file qpixmap_mac.cpp.

Referenced by QMacPasteboardMimeHTMLText::convertFromMime(), QMacPasteboardMimeTiff::convertToMime(), QWizardPrivate::findDefaultBackgroundPixmap(), qt_mac_grabDisplayRect(), and qt_mac_grabScreenRect().

1272 {
1273  const size_t w = CGImageGetWidth(image),
1274  h = CGImageGetHeight(image);
1275  QPixmap ret(w, h);
1276  ret.fill(Qt::transparent);
1277  CGRect rect = CGRectMake(0, 0, w, h);
1279  qt_mac_drawCGImage(ctx, &rect, image);
1280  CGContextRelease(ctx);
1281  return ret;
1282 }
struct CGRect CGRect
#define ctx
Definition: qgl.cpp:6094
friend CGContextRef qt_mac_cg_context(const QPaintDevice *)
Returns the CoreGraphics CGContextRef of the paint device.
OSStatus qt_mac_drawCGImage(CGContextRef inContext, const CGRect *inBounds, CGImageRef inImage)
QRect rect() const
Returns the pixmap&#39;s enclosing rectangle.
Definition: qpixmap.cpp:676
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
struct CGContext * CGContextRef

◆ fromWinHBITMAP()

QPixmap QPixmap::fromWinHBITMAP ( HBITMAP  bitmap,
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(), {QPixmap::Pixmap Conversion}{Pixmap Conversion}

Definition at line 179 of file qpixmap_win.cpp.

Referenced by QGLContext::choosePixelFormat(), IPictureToQPixmap(), and QAxHostWidget::paintEvent().

180 {
181  // Verify size
182  BITMAP bitmap_info;
183  memset(&bitmap_info, 0, sizeof(BITMAP));
184 
185  int res = GetObject(bitmap, sizeof(BITMAP), &bitmap_info);
186  if (!res) {
187  qErrnoWarning("QPixmap::fromWinHBITMAP(), failed to get bitmap info");
188  return QPixmap();
189  }
190  int w = bitmap_info.bmWidth;
191  int h = bitmap_info.bmHeight;
192 
193  BITMAPINFO bmi;
194  memset(&bmi, 0, sizeof(bmi));
195  bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
196  bmi.bmiHeader.biWidth = w;
197  bmi.bmiHeader.biHeight = -h;
198  bmi.bmiHeader.biPlanes = 1;
199  bmi.bmiHeader.biBitCount = 32;
200  bmi.bmiHeader.biCompression = BI_RGB;
201  bmi.bmiHeader.biSizeImage = w * h * 4;
202 
203  QImage result;
204  // Get bitmap bits
205  uchar *data = (uchar *) qMalloc(bmi.bmiHeader.biSizeImage);
206 
207  HDC display_dc = GetDC(0);
208  if (GetDIBits(display_dc, bitmap, 0, h, data, &bmi, DIB_RGB_COLORS)) {
209 
211  uint mask = 0;
212  if (format == NoAlpha) {
213  imageFormat = QImage::Format_RGB32;
214  mask = 0xff000000;
215  }
216 
217  // Create image and copy data into image.
218  QImage image(w, h, imageFormat);
219  if (!image.isNull()) { // failed to alloc?
220  int bytes_per_line = w * sizeof(QRgb);
221  for (int y=0; y<h; ++y) {
222  QRgb *dest = (QRgb *) image.scanLine(y);
223  const QRgb *src = (const QRgb *) (data + y * bytes_per_line);
224  for (int x=0; x<w; ++x) {
225  const uint pixel = src[x];
226  if ((pixel & 0xff000000) == 0 && (pixel & 0x00ffffff) != 0)
227  dest[x] = pixel | 0xff000000;
228  else
229  dest[x] = pixel | mask;
230  }
231  }
232  }
233  result = image;
234  } else {
235  qWarning("QPixmap::fromWinHBITMAP(), failed to get bitmap bits");
236  }
237  ReleaseDC(0, display_dc);
238  qFree(data);
239  return fromImage(result);
240 }
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition: qpixmap.cpp:2197
Format
The following image formats are available in Qt.
Definition: qimage.h:91
unsigned int QRgb
Definition: qrgb.h:53
QPixmap()
Constructs a null pixmap.
Definition: qpixmap.cpp:174
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
Q_CORE_EXPORT void qFree(void *ptr)
Definition: qmalloc.cpp:58
#define GetDIBits(a, b, c, d, e, f, g)
Q_CORE_EXPORT void * qMalloc(size_t size)
Definition: qmalloc.cpp:53
unsigned char uchar
Definition: qglobal.h:994
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
unsigned int uint
Definition: qglobal.h:996
QBitmap mask() const
Extracts a bitmap mask from the pixmap&#39;s alpha channel.
Definition: qpixmap.cpp:2077
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

◆ fromWinHICON()

QPixmap QPixmap::fromWinHICON ( HICON  icon)
static
Since
4.6

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

Warning
This function is only available on Windows.
See also
toWinHICON(), {QPixmap::Pixmap Conversion}{Pixmap Conversion}

Definition at line 386 of file qpixmap_win.cpp.

Referenced by QFileIconProviderPrivate::getWinIcon(), loadIconFromShell32(), QWindowsStyle::standardIconImplementation(), QWindowsStyle::standardPixmap(), and toWinHICON().

387 {
388  HDC screenDevice = GetDC(0);
389  HDC hdc = CreateCompatibleDC(screenDevice);
390  ReleaseDC(0, screenDevice);
391 
392  ICONINFO iconinfo;
393  bool result = GetIconInfo(icon, &iconinfo);
394  if (!result)
395  qWarning("QPixmap::fromWinHICON(), failed to GetIconInfo()");
396 
397  int w = 0;
398  int h = 0;
399  if (!iconinfo.xHotspot || !iconinfo.yHotspot) {
400  // We could not retrieve the icon size via GetIconInfo,
401  // so we try again using the icon bitmap.
402  BITMAP bm;
403  int result = GetObject(iconinfo.hbmColor, sizeof(BITMAP), &bm);
404  if (!result) result = GetObject(iconinfo.hbmMask, sizeof(BITMAP), &bm);
405  if (!result) {
406  qWarning("QPixmap::fromWinHICON(), failed to retrieve icon size");
407  return QPixmap();
408  }
409  w = bm.bmWidth;
410  h = bm.bmHeight;
411  } else {
412  // x and y Hotspot describes the icon center
413  w = iconinfo.xHotspot * 2;
414  h = iconinfo.yHotspot * 2;
415  }
416  const DWORD dwImageSize = w * h * 4;
417 
418  BITMAPINFO bmi;
419  memset(&bmi, 0, sizeof(bmi));
420  bmi.bmiHeader.biSize = sizeof(BITMAPINFO);
421  bmi.bmiHeader.biWidth = w;
422  bmi.bmiHeader.biHeight = -h;
423  bmi.bmiHeader.biPlanes = 1;
424  bmi.bmiHeader.biBitCount = 32;
425  bmi.bmiHeader.biCompression = BI_RGB;
426  bmi.bmiHeader.biSizeImage = dwImageSize;
427 
428  uchar* bits;
429 
430  HBITMAP winBitmap = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**) &bits, 0, 0);
431  if (winBitmap )
432  memset(bits, 0xff, dwImageSize);
433  if (!winBitmap) {
434  qWarning("QPixmap::fromWinHICON(), failed to CreateDIBSection()");
435  return QPixmap();
436  }
437 
438  HGDIOBJ oldhdc = (HBITMAP)SelectObject(hdc, winBitmap);
439  if (!DrawIconEx( hdc, 0, 0, icon, w, h, 0, 0, DI_NORMAL))
440  qWarning("QPixmap::fromWinHICON(), failed to DrawIcon()");
441 
442  uint mask = 0xff000000;
443  // Create image and copy data into image.
444  QImage image(w, h, QImage::Format_ARGB32);
445 
446  if (!image.isNull()) { // failed to alloc?
447  int bytes_per_line = w * sizeof(QRgb);
448  for (int y=0; y < h; ++y) {
449  QRgb *dest = (QRgb *) image.scanLine(y);
450  const QRgb *src = (const QRgb *) (bits + y * bytes_per_line);
451  for (int x=0; x < w; ++x) {
452  dest[x] = src[x];
453  }
454  }
455  }
456  if (!DrawIconEx( hdc, 0, 0, icon, w, h, 0, 0, DI_MASK))
457  qWarning("QPixmap::fromWinHICON(), failed to DrawIcon()");
458  if (!image.isNull()) { // failed to alloc?
459  int bytes_per_line = w * sizeof(QRgb);
460  for (int y=0; y < h; ++y) {
461  QRgb *dest = (QRgb *) image.scanLine(y);
462  const QRgb *src = (const QRgb *) (bits + y * bytes_per_line);
463  for (int x=0; x < w; ++x) {
464  if (!src[x])
465  dest[x] = dest[x] | mask;
466  }
467  }
468  }
469  SelectObject(hdc, oldhdc); //restore state
470  DeleteObject(winBitmap);
471  DeleteDC(hdc);
472  return QPixmap::fromImage(image);
473 }
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition: qpixmap.cpp:2197
unsigned int QRgb
Definition: qrgb.h:53
QPixmap()
Constructs a null pixmap.
Definition: qpixmap.cpp:174
unsigned char uchar
Definition: qglobal.h:994
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
unsigned int uint
Definition: qglobal.h:996
QBitmap mask() const
Extracts a bitmap mask from the pixmap&#39;s alpha channel.
Definition: qpixmap.cpp:2077

◆ grabWidget() [1/2]

QPixmap QPixmap::grabWidget ( 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 QWidget::paintEvent() .
See also
grabWindow()

Definition at line 1188 of file qpixmap.cpp.

Referenced by QAxServerBase::Draw(), QRollEffect::QRollEffect(), and QAlphaWidget::run().

1189 {
1190  if (!widget)
1191  return QPixmap();
1192 
1194  sendResizeEvents(widget);
1195 
1196  widget->d_func()->prepareToRender(QRegion(),
1198 
1199  QRect r(rect);
1200  if (r.width() < 0)
1201  r.setWidth(widget->width() - rect.x());
1202  if (r.height() < 0)
1203  r.setHeight(widget->height() - rect.y());
1204 
1205  if (!r.intersects(widget->rect()))
1206  return QPixmap();
1207 
1208  QPixmap res(r.size());
1209  if (!qt_widget_private(widget)->isOpaque)
1210  res.fill(Qt::transparent);
1211 
1212  widget->d_func()->render(&res, QPoint(), r, QWidget::DrawWindowBackground
1214  return res;
1215 }
QPixmap()
Constructs a null pixmap.
Definition: qpixmap.cpp:174
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
static void sendResizeEvents(QWidget *target)
Definition: qpixmap.cpp:1145
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Definition: qpixmap.cpp:1080
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QRect rect() const
Returns the pixmap&#39;s enclosing rectangle.
Definition: qpixmap.cpp:676
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
Q_GUI_EXPORT QWidgetPrivate * qt_widget_private(QWidget *widget)
Definition: qwidget.cpp:12920
void render(QPaintDevice *target, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
Renders the sourceRegion of this widget into the target using renderFlags to determine how to render...
Definition: qwidget.cpp:5372

◆ grabWidget() [2/2]

static QPixmap QPixmap::grabWidget ( QWidget widget,
int  x = 0,
int  y = 0,
int  w = -1,
int  h = -1 
)
inlinestatic

Definition at line 128 of file qpixmap.h.

129  { return grabWidget(widget, QRect(x, y, w, h)); }
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
static QPixmap grabWidget(QWidget *widget, const QRect &rect)
Creates a pixmap and paints the given widget, restricted by the given rectangle, in it...
Definition: qpixmap.cpp:1188

◆ grabWindow()

QPixmap QPixmap::grabWindow ( WId  window,
int  x = 0,
int  y = 0,
int  w = -1,
int  h = -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(), {Screenshot Example}

Definition at line 972 of file qpixmap_mac.cpp.

Referenced by QWindowsVistaStyle::drawComplexControl(), QAlphaWidget::run(), QWhatsThat::showEvent(), and QX11PixmapData::transformed().

973 {
975  if (widget == 0)
976  return QPixmap();
977 
978  if(w == -1)
979  w = widget->width() - x;
980  if(h == -1)
981  h = widget->height() - y;
982 
983  QPoint globalCoord(0, 0);
984  globalCoord = widget->mapToGlobal(globalCoord);
985  QRect rect(globalCoord.x() + x, globalCoord.y() + y, w, h);
986 
987 #ifdef QT_MAC_USE_COCOA
988 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
990  return qt_mac_grabScreenRect_10_6(rect);
991  else
992 #endif
993  return qt_mac_grabScreenRect(rect);
994 #else
995 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
997  return qt_mac_grabScreenRect(rect);
998  } else
999 #endif
1000  {
1001  return qt_mac_grabScreenRect_10_3(x, y, w, h, widget);
1002  }
1003 #endif // ifdef Q_WS_MAC64
1004 }
QPixmap()
Constructs a null pixmap.
Definition: qpixmap.cpp:174
QPointer< QWidget > widget
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
NSWindow * window
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
static QWidget * find(WId)
Returns a pointer to the widget with window identifer/handle id.
Definition: qwidget.cpp:2517
static QPixmap qt_mac_grabScreenRect_10_3(int x, int y, int w, int h, QWidget *widget)
static QPixmap qt_mac_grabScreenRect(const QRect &rect)
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QRect rect() const
Returns the pixmap&#39;s enclosing rectangle.
Definition: qpixmap.cpp:676
static const MacVersion MacintoshVersion
the version of the Macintosh operating system on which the application is run (Mac only)...
Definition: qglobal.h:1646
QPoint mapToGlobal(const QPoint &) const
Translates the widget coordinate pos to global screen coordinates.

◆ handle()

Qt::HANDLE QPixmap::handle ( ) const

Returns the pixmap's handle to the device context.

Note that, since QPixmap make use of Implicit {Data Sharing}{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.
Since 4.8, pixmaps do not have an X11 handle unless created with QPixmap::fromX11Pixmap() , or if the native graphics system is explicitly enabled.
See also
detach()
QApplication::setGraphicsSystem()

Definition at line 1299 of file qpixmap.cpp.

Referenced by QX11PixmapData::bitmap_to_mask(), QX11PaintEngine::drawPixmap(), QX11PaintEngine::drawTiledPixmap(), QX11GLWindowSurface::flush(), QX11WindowSurface::flush(), QRasterWindowSurface::flush(), QX11GLWindowSurface::grabWidget(), QX11WindowSurface::grabWidget(), QMeeGoLivePixmapData::handle(), QMeeGoLivePixmapData::initializeThroughEGLImage(), QX11PixmapData::mask_to_bitmap(), menuItemEntry(), QGLOverlayWidget::paintGL(), QCursor::QCursor(), qstring_to_xtp(), QX11GLWindowSurface::scroll(), QX11WindowSurface::scroll(), QX11WindowSurface::setGeometry(), QX11PixmapData::setMask(), QX11PixmapData::transformed(), QX11PaintEngine::updateBrush(), and QX11Data::xdndMimeDataForAtom().

1300 {
1301 #if defined(Q_WS_X11)
1302  const QPixmapData *pd = pixmapData();
1303  if (pd && pd->classId() == QPixmapData::X11Class)
1304  return static_cast<const QX11PixmapData*>(pd)->handle();
1305 #endif
1306  return 0;
1307 }
ClassId classId() const
QPixmapData * pixmapData() const
Definition: qpixmap.cpp:2277

◆ hasAlpha()

bool QPixmap::hasAlpha ( ) const

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

See also
hasAlphaChannel(), mask()

Definition at line 1938 of file qpixmap.cpp.

Referenced by QAlphaPaintEngine::drawPixmap(), QGL2PaintEngineEx::drawPixmap(), QGL2PaintEngineExPrivate::drawPixmapFragments(), QAlphaPaintEngine::drawTiledPixmap(), QX11PaintEngine::drawTiledPixmap(), QX11PaintEnginePrivate::fillPolygon_dev(), QStyleSheetBorderData::isOpaque(), QSplashScreen::setPixmap(), and QPainterPrivate::updateEmulationSpecifier().

1939 {
1940 #if defined(Q_WS_X11)
1941  if (data && data->hasAlphaChannel())
1942  return true;
1943  QPixmapData *pd = pixmapData();
1944  if (pd && pd->classId() == QPixmapData::X11Class) {
1945  QX11PixmapData *x11Data = static_cast<QX11PixmapData*>(pd);
1946 #ifndef QT_NO_XRENDER
1947  if (x11Data->picture && x11Data->d == 32)
1948  return true;
1949 #endif
1950  if (x11Data->d == 1 || x11Data->x11_mask)
1951  return true;
1952  }
1953  return false;
1954 #else
1955  return data && data->hasAlphaChannel();
1956 #endif
1957 }
Qt::HANDLE picture
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
ClassId classId() const
virtual bool hasAlphaChannel() const =0
Qt::HANDLE x11_mask
QPixmapData * pixmapData() const
Definition: qpixmap.cpp:2277

◆ hasAlphaChannel()

bool QPixmap::hasAlphaChannel ( ) const

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

See also
hasAlpha()

Definition at line 1965 of file qpixmap.cpp.

Referenced by CapabilitiesToStateMask::canBlitterDrawPixmap(), depth(), QDirectFBPaintEngine::drawPixmap(), QPaintEngine::drawTiledPixmap(), fill(), QMeeGoLivePixmapData::initializeThroughEGLImage(), QBrush::isOpaque(), and qDrawPlainRect().

1966 {
1967  return data && data->hasAlphaChannel();
1968 }
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
virtual bool hasAlphaChannel() const =0

◆ height()

int QPixmap::height ( ) const

Returns the height of the pixmap.

See also
size(), {QPixmap::Pixmap Information}{Pixmap Information}

Definition at line 645 of file qpixmap.cpp.

Referenced by QX11WindowSurface::beginPaint(), QX11PixmapData::bitmap_to_mask(), copy(), QXlibCursor::createCursorBitmap(), QOleDropSource::createCursors(), QWSDisplay::defineCursor(), depth(), QDragManager::drag(), QAxServerBase::Draw(), QTreeViewPrivate::drawAnimatedOperation(), QRenderRule::drawBackgroundImage(), QMacStylePrivate::drawCombobox(), QCommonStyle::drawControl(), QWindowsCEStyle::drawControl(), QWindowsVistaStyle::drawControl(), QPlastiqueStyle::drawControl(), QWindowsMobileStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsXPStyle::drawControl(), QWindowsStyle::drawControl(), QGtkStyle::drawControl(), QMotifStyle::drawControl(), QMacStyle::drawControl(), QStyleSheetStyle::drawControl(), QDeclarativeTextPrivate::drawOutline(), QWin32PrintEngine::drawPixmap(), QCoreGraphicsPaintEngine::drawPixmap(), QGL2PaintEngineEx::drawPixmap(), QOpenGLPaintEngine::drawPixmap(), QPainter::drawPixmap(), QMacStylePrivate::drawTableHeader(), drawTextItemDecoration(), QPSPrintEngine::drawTiledPixmap(), QWin32PrintEngine::drawTiledPixmap(), QX11PaintEngine::drawTiledPixmap(), QOpenGLPaintEngine::drawTiledPixmap(), QPaintEngine::drawTiledPixmap(), QPainter::drawTiledPixmap(), QBlitterPaintEngine::fillRect(), QMacStylePrivate::generateBackgroundPattern(), getPixmapSize(), QDeclarativePixmap::height(), QMeeGoLivePixmapData::initializeThroughEGLImage(), QPixmapCache::insert(), QGLBlurTextureCache::insertBlurTextureInfo(), QStyle::itemPixmapRect(), QX11PixmapData::mask_to_bitmap(), menuItemEntry(), QColorWell::mouseMoveEvent(), QColorShowLabel::mouseMoveEvent(), QAxHostWidget::paintEvent(), QWizard::paintEvent(), QColorLuminancePicker::paintEvent(), QGLOverlayWidget::paintGL(), QMacStyle::polish(), QCursor::QCursor(), qDrawPlainRect(), qt_draw_tile(), qt_fill_tile(), qt_mac_cg_context(), qt_mac_draw_pattern(), QPixmapCache::replace(), scaled(), scaledToHeight(), setAlphaChannel(), QCursorData::setBitmap(), QShapedPixmapWidget::setPixmap(), QMacStyle::standardIconImplementation(), QWindowsMobileStyle::standardPixmap(), QGL2PaintEngineExPrivate::updateBrushTexture(), QGL2PaintEngineExPrivate::updateBrushUniforms(), QGLContextPrivate::updateFormatVersion(), QGLContext::updatePaintDevice(), and QGraphicsPixmapItemPrivate::updateShape().

646 {
647  return data ? data->height() : 0;
648 }
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
int height() const

◆ init() [1/2]

void QPixmap::init ( int  w,
int  h,
Type  type = PixmapType 
)
private

Definition at line 128 of file qpixmap.cpp.

Referenced by handle(), and QPixmap().

129 {
130  init(w, h, int(type));
131 }
int type
Definition: qmetatype.cpp:239
void init(int, int, Type=PixmapType)
Definition: qpixmap.cpp:128

◆ init() [2/2]

void QPixmap::init ( int  w,
int  h,
int  type 
)
private

Definition at line 135 of file qpixmap.cpp.

136 {
137  if (qt_appType == QApplication::Tty) {
138  qWarning("QPixmap: Cannot create a QPixmap when no GUI is being used");
139  data = 0;
140  return;
141  }
142 
143  if ((w > 0 && h > 0) || type == QPixmapData::BitmapType)
145  else
146  data = 0;
147 }
int type
Definition: qmetatype.cpp:239
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
Q_CORE_EXPORT void qWarning(const char *,...)
QApplication::Type qt_appType
static QPixmapData * create(int w, int h, PixelType type)
Definition: qpixmapdata.cpp:55

◆ initAlphaPixmap()

void QPixmap::initAlphaPixmap ( uchar bytes,
int  length,
struct tagBITMAPINFO *  bmi 
)
private

◆ isDetached()

bool QPixmap::isDetached ( ) const
Warning
This function is not part of the public interface.

Definition at line 1495 of file qpixmap.cpp.

Referenced by qIsDetached().

1496 {
1497  return data && data->ref == 1;
1498 }
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
QAtomicInt ref

◆ isNull()

bool QPixmap::isNull ( ) 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.

Definition at line 615 of file qpixmap.cpp.

Referenced by _q_paintIntoCache(), QMessageBox::aboutQt(), QSvgIconEngine::actualSize(), QSvgIconEngine::addFile(), QPixmapIconEngine::addFile(), QIcon::addPixmap(), QPixmapIconEngine::addPixmap(), QCoreGraphicsPaintEngine::begin(), QPainter::begin(), QX11WindowSurface::beginPaint(), QPixmapIconEngine::bestMatch(), bestSizeMatch(), QX11PixmapData::bitmap_to_mask(), cacheKey(), convertFromImage(), copy(), create32BitCursor(), QOleDropSource::createCursors(), QSystemTrayIconSys::createIcon(), createPixmapDataSync(), depth(), QDragManager::drag(), QVGPixmapConvolutionFilter::draw(), QVGPixmapColorizeFilter::draw(), QVGPixmapDropShadowFilter::draw(), QVGPixmapBlurFilter::draw(), QPixmapConvolutionFilter::draw(), QPixmapBlurFilter::draw(), QGraphicsColorizeEffect::draw(), QPixmapColorizeFilter::draw(), QPixmapDropShadowFilter::draw(), QGraphicsBlurEffect::draw(), QGraphicsDropShadowEffect::draw(), QGraphicsOpacityEffect::draw(), QRenderRule::drawBackgroundImage(), QPlastiqueStyle::drawComplexControl(), QCommonStyle::drawControl(), QWindowsCEStyle::drawControl(), QWindowsVistaStyle::drawControl(), QPlastiqueStyle::drawControl(), QWindowsXPStyle::drawControl(), QWindowsStyle::drawControl(), QStyleSheetStyle::drawControl(), QItemDelegate::drawDecoration(), QGraphicsScenePrivate::drawItemHelper(), QPdfEngine::drawPixmap(), QCoreGraphicsPaintEngine::drawPixmap(), QPainter::drawPixmap(), QPaintEngineEx::drawPixmapFragments(), QPainter::drawPixmapFragments(), QPlastiqueStyle::drawPrimitive(), QPainter::drawTiledPixmap(), fill(), QSystemTrayIconSys::findTrayGeometry(), QRenderRule::fixupBorder(), QX11GLWindowSurface::flush(), QX11WindowSurface::flush(), getPixmap(), getPixmapSize(), QFileIconProviderPrivate::getWinIcon(), QX11GLWindowSurface::grabWidget(), QX11WindowSurface::grabWidget(), handle(), QPixmapIconEngineEntry::isNull(), QFrameInfo::isValid(), QWizardPrivate::layoutInfoForCurrentPage(), QTextDocument::loadResource(), menuItemEntry(), operator<<(), QBitmap::operator=(), QBrush::operator==(), QDecorationWindows::paintButton(), QDecorationDefault::paintButton(), QWizard::paintEvent(), QSvgIconEngine::pixmap(), QGraphicsEffectSource::pixmap(), QPixmapIconEngine::pixmap(), QWizardPage::pixmap(), pixmapsAreEqual(), QStyleSheetStyle::polish(), qBrushDark(), qBrushLight(), qBrushSetAlphaF(), QCursor::QCursor(), QPixmapToIPicture(), QRegion::QRegion(), qstring_to_xtp(), qt_bitmapToRegion(), qt_createIcon(), qt_mac_create_iconref(), qt_mac_display_change_callbk(), qt_mac_set_app_icon(), qt_toRasterPixmap(), qt_toX11Pixmap(), save(), scaled(), scaledToHeight(), scaledToWidth(), QX11GLWindowSurface::scroll(), QX11WindowSurface::scroll(), scroll(), serialNumber(), setAlphaChannel(), QGL2PaintEngineExPrivate::setBrush(), QBrush::setColor(), QDrag::setDragCursor(), QX11WindowSurface::setGeometry(), QMacPixmapData::setMask(), QX11PixmapData::setMask(), setMask(), QDeclarativePixmap::setPixmap(), QShapedPixmapWidget::setPixmap(), QTexturedBrushData::setPixmap(), QBrush::setTexture(), QWizardHeader::setup(), QWorkspacePrivate::showMaximizeControls(), QSystemTrayIconPrivate::showMessage_sys(), QLabelPrivate::sizeForWidth(), QWindowsStyle::standardIconImplementation(), QCommonStyle::standardPixmap(), QWindowsStyle::standardPixmap(), toImage(), toWinHBITMAP(), toWinHICON(), transformed(), QCursorData::update(), QGraphicsPixmapItemPrivate::updateShape(), QPixmapIconEngine::virtual_hook(), and QPixmapIconEngine::write().

616 {
617  return !data || data->isNull();
618 }
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
bool isNull() const

◆ isQBitmap()

bool QPixmap::isQBitmap ( ) const

◆ load()

bool QPixmap::load ( 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(), {QPixmap::Reading and Writing Image Files}{Reading and Writing Image Files}

Definition at line 930 of file qpixmap.cpp.

Referenced by handle(), QBitmap::QBitmap(), and QPixmap().

931 {
932  if (fileName.isEmpty())
933  return false;
934 
935  QFileInfo info(fileName);
936  QString key = QLatin1Literal("qt_pixmap")
937  % info.absoluteFilePath()
938  % HexString<uint>(info.lastModified().toTime_t())
939  % HexString<quint64>(info.size())
941 
942  // Note: If no extension is provided, we try to match the
943  // file against known plugin extensions
944  if (!info.completeSuffix().isEmpty() && !info.exists())
945  return false;
946 
947  if (QPixmapCache::find(key, *this))
948  return true;
949 
951  if (tmp->fromFile(fileName, format, flags)) {
952  data = tmp.take();
953  QPixmapCache::insert(key, *this);
954  return true;
955  }
956 
957  return false;
958 }
The QLatin1Literal class provides a thin wrapper around string literals used in source code...
static mach_timebase_info_data_t info
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QPixmap * find(const QString &key)
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
PixelType pixelType() const
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
PixelType type
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
int key
static QPixmapData * create(int w, int h, PixelType type)
Definition: qpixmapdata.cpp:55
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60

◆ loadFromData() [1/2]

bool QPixmap::loadFromData ( 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(), {QPixmap::Reading and Writing Image Files}{Reading and Writing Image Files}

Definition at line 979 of file qpixmap.cpp.

Referenced by QTextHtmlParserNode::applyBackgroundImage(), getPixmap(), handle(), and QTextDocument::loadResource().

980 {
981  if (len == 0 || buf == 0)
982  return false;
983 
984  if (!data)
986 
987  return data->fromData(buf, len, format, flags);
988 }
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
virtual bool fromData(const uchar *buffer, uint len, const char *format, Qt::ImageConversionFlags flags)
static QPixmapData * create(int w, int h, PixelType type)
Definition: qpixmapdata.cpp:55

◆ loadFromData() [2/2]

bool QPixmap::loadFromData ( const QByteArray data,
const char *  format = 0,
Qt::ImageConversionFlags  flags = Qt::AutoColor 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Loads a pixmap from the binary data using the specified format and conversion flags.

Definition at line 312 of file qpixmap.h.

314 {
315  return loadFromData(reinterpret_cast<const uchar *>(buf.constData()), buf.size(), format, flags);
316 }
bool loadFromData(const uchar *buf, uint len, const char *format=0, Qt::ImageConversionFlags flags=Qt::AutoColor)
Loads a pixmap from the len first bytes of the given binary data.
Definition: qpixmap.cpp:979

◆ mask()

QBitmap QPixmap::mask ( ) 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(), {QPixmap::Pixmap Information}{Pixmap Information}

Definition at line 2077 of file qpixmap.cpp.

Referenced by create32BitCursor(), fromWinHBITMAP(), fromWinHICON(), isServerProcess(), QCursor::QCursor(), qDrawPlainRect(), QShapedPixmapWidget::setPixmap(), toWinHICON(), and QGraphicsPixmapItemPrivate::updateShape().

2078 {
2079  return data ? data->mask() : QBitmap();
2080 }
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
virtual QBitmap mask() const
friend class QBitmap
Definition: qpixmap.h:279

◆ metric()

int QPixmap::metric ( PaintDeviceMetric  metric) const
protectedvirtual
Warning
This function is not part of the public interface.

Reimplemented from QPaintDevice.

Definition at line 1973 of file qpixmap.cpp.

1974 {
1975  return data ? data->metric(metric) : 0;
1976 }
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
int metric(PaintDeviceMetric) const
Definition: qpixmap.cpp:1973
virtual int metric(QPaintDevice::PaintDeviceMetric metric) const =0

◆ numCols()

int QPixmap::numCols ( ) const
Warning
This function is not part of the public interface.
See also
colorCount()

Definition at line 125 of file qpixmap_qws.cpp.

126 {
127  return colorCount();
128 }
int colorCount() const

◆ operator QVariant()

QPixmap::operator QVariant ( ) const

Returns the pixmap as a QVariant.

Definition at line 499 of file qpixmap.cpp.

500 {
501  return QVariant(QVariant::Pixmap, this);
502 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92

◆ operator!()

bool QPixmap::operator! ( ) const
inline

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

See also
isNull()

Definition at line 226 of file qpixmap.h.

226 { return isNull(); }
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615

◆ operator=()

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

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

See also
copy(), QPixmap()

Definition at line 471 of file qpixmap.cpp.

Referenced by QBitmap::clear(), handle(), QBitmap::operator=(), and QPixmap().

472 {
473  if (paintingActive()) {
474  qWarning("QPixmap::operator=: Cannot assign to pixmap during painting");
475  return *this;
476  }
477  if (pixmap.paintingActive()) { // make a deep copy
478  *this = pixmap.copy();
479  } else {
480  data = pixmap.data;
481  }
482  return *this;
483 }
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
bool paintingActive() const
Definition: qpaintdevice.h:170
Q_CORE_EXPORT void qWarning(const char *,...)
QPixmap copy(int x, int y, int width, int height) const
Returns a deep copy of the subset of the pixmap that is specified by the rectangle QRect( x...
Definition: qpixmap.h:302

◆ paintEngine()

QPaintEngine * QPixmap::paintEngine ( ) const
virtual
Warning
This function is not part of the public interface.

Implements QPaintDevice.

Definition at line 2059 of file qpixmap.cpp.

2060 {
2061  return data ? data->paintEngine() : 0;
2062 }
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
virtual QPaintEngine * paintEngine() const =0

◆ pixmapData()

QPixmapData * QPixmap::pixmapData ( ) const
Warning
This function is not part of the public interface.

Definition at line 2277 of file qpixmap.cpp.

Referenced by QRasterPaintEngine::begin(), CapabilitiesToStateMask::canBlitterDrawPixmap(), CapabilitiesToStateMask::canBlitterDrawPixmapOpacity(), QDirectFBCursor::changeCursor(), depth(), detach(), QVGPixmapConvolutionFilter::draw(), QVGPixmapColorizeFilter::draw(), QVGPixmapDropShadowFilter::draw(), QVGPixmapBlurFilter::draw(), QVGCompositionHelper::drawCursorPixmap(), QVolatileImagePaintEngine::drawPixmap(), QDirectFBPaintEngine::drawPixmap(), QVGPaintEngine::drawPixmap(), QRasterPaintEngine::drawPixmap(), QVGPaintEngine::drawPixmapFragments(), QDirectFbBlitter::drawPixmapOpacity(), QDirectFBPaintEngine::drawTiledPixmap(), QDirectFBPaintEnginePrivate::drawTiledPixmap(), QRasterPaintEngine::drawTiledPixmap(), QDirectFBPaintEngine::fillRect(), QX11GLWindowSurface::grabWidget(), handle(), hasAlpha(), qPixmapToVGImage(), qt_directfb_surface_for_pixmap(), QVGPaintEnginePrivate::setBrush(), QX11WindowSurface::setGeometry(), and QMeeGoGraphicsSystem::updateEGLSharedImagePixmap().

2278 {
2279  if (data) {
2280  QPixmapData* pm = data.data();
2281  return pm->runtimeData() ? pm->runtimeData() : pm;
2282  }
2283 
2284  return 0;
2285 }
virtual QPixmapData * runtimeData() const
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145

◆ qwsBits()

const uchar * QPixmap::qwsBits ( ) const
Warning
This function is not part of the public interface.
Since
4.1

Definition at line 140 of file qpixmap_qws.cpp.

141 {
142  if (data && data->classId() == QPixmapData::RasterClass) {
143  const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data());
144  return d->image.bits();
145  }
146 
147  return 0;
148 }
double d
Definition: qnumeric_p.h:62
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
ClassId classId() const
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946

◆ qwsBytesPerLine()

int QPixmap::qwsBytesPerLine ( ) const
Warning
This function is not part of the public interface.
Since
4.1

Definition at line 150 of file qpixmap_qws.cpp.

151 {
152  if (data && data->classId() == QPixmapData::RasterClass) {
153  const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data());
154  return d->image.bytesPerLine();
155  }
156 
157  return 0;
158 }
double d
Definition: qnumeric_p.h:62
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
ClassId classId() const

◆ rect()

QRect QPixmap::rect ( ) const

◆ save() [1/2]

bool QPixmap::save ( 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
{QPixmap::Reading and Writing Image Files}{Reading and Writing Image Files}

Definition at line 1016 of file qpixmap.cpp.

1017 {
1018  if (isNull())
1019  return false; // nothing to save
1020  QImageWriter writer(fileName, format);
1021  return doImageIO(&writer, quality);
1022 }
The QImageWriter class provides a format independent interface for writing images to files or other d...
Definition: qimagewriter.h:59
bool doImageIO(QImageWriter *io, int quality) const
Definition: qpixmap.cpp:1047
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615

◆ save() [2/2]

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

This function writes a QPixmap to the given device using the specified image file format and quality factor.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This can be used, for example, to save a pixmap directly into a QByteArray:

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

Definition at line 1037 of file qpixmap.cpp.

1038 {
1039  if (isNull())
1040  return false; // nothing to save
1041  QImageWriter writer(device, format);
1042  return doImageIO(&writer, quality);
1043 }
The QImageWriter class provides a format independent interface for writing images to files or other d...
Definition: qimagewriter.h:59
bool doImageIO(QImageWriter *io, int quality) const
Definition: qpixmap.cpp:1047
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615

◆ scaled() [1/2]

QPixmap QPixmap::scaled ( int  w,
int  h,
Qt::AspectRatioMode  aspectMode = Qt::IgnoreAspectRatio,
Qt::TransformationMode  mode = Qt::FastTransformation 
) const
inline

Definition at line 132 of file qpixmap.h.

Referenced by QGL2PaintEngineEx::drawPixmap(), QOpenGLPaintEngine::drawPixmap(), QGL2PaintEngineEx::drawPixmapFragments(), QPixmapIconEngine::pixmap(), QWidgetPrivate::setWindowIcon_sys(), and QGL2PaintEngineExPrivate::updateBrushTexture().

134  { return scaled(QSize(w, h), aspectMode, mode); }
QPixmap scaled(int w, int h, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
Definition: qpixmap.h:132
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ scaled() [2/2]

QPixmap QPixmap::scaled ( const QSize s,
Qt::AspectRatioMode  aspectMode = Qt::IgnoreAspectRatio,
Qt::TransformationMode  mode = Qt::FastTransformation 
) const

Definition at line 1603 of file qpixmap.cpp.

1604 {
1605  if (isNull()) {
1606  qWarning("QPixmap::scaled: Pixmap is a null pixmap");
1607  return QPixmap();
1608  }
1609  if (s.isEmpty())
1610  return QPixmap();
1611 
1612  QSize newSize = size();
1613  newSize.scale(s, aspectMode);
1614  newSize.rwidth() = qMax(newSize.width(), 1);
1615  newSize.rheight() = qMax(newSize.height(), 1);
1616  if (newSize == size())
1617  return *this;
1618 
1619  QTransform wm = QTransform::fromScale((qreal)newSize.width() / width(),
1620  (qreal)newSize.height() / height());
1621  QPixmap pix = transformed(wm, mode);
1622  return pix;
1623 }
double qreal
Definition: qglobal.h:1193
QPixmap()
Constructs a null pixmap.
Definition: qpixmap.cpp:174
int width() const
Returns the width of the pixmap.
Definition: qpixmap.cpp:630
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
QPixmap transformed(const QMatrix &, Qt::TransformationMode mode=Qt::FastTransformation) const
This convenience function loads the matrix into a QTransform and calls the overloaded function...
Definition: qpixmap.cpp:1723
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
int width() const
Returns the width.
Definition: qsize.h:126
Q_CORE_EXPORT void qWarning(const char *,...)
int & rheight()
Returns a reference to the height.
Definition: qsize.h:144
int height() const
Returns the height.
Definition: qsize.h:129
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
void scale(int w, int h, Qt::AspectRatioMode mode)
Scales the size to a rectangle with the given width and height, according to the specified mode: ...
Definition: qsize.h:138
int height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
static QTransform fromScale(qreal dx, qreal dy)
Creates a matrix which corresponds to a scaling of sx horizontally and sy vertically.
Definition: qtransform.cpp:528
bool isEmpty() const
Returns true if either of the width and height is less than or equal to 0; otherwise returns false...
Definition: qsize.h:120
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
int & rwidth()
Returns a reference to the width.
Definition: qsize.h:141
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ scaledToHeight()

QPixmap QPixmap::scaledToHeight ( int  h,
Qt::TransformationMode  mode = Qt::FastTransformation 
) const

Definition at line 1673 of file qpixmap.cpp.

Referenced by QWindowsMobileStyle::standardPixmap().

1674 {
1675  if (isNull()) {
1676  qWarning("QPixmap::scaleHeight: Pixmap is a null pixmap");
1677  return copy();
1678  }
1679  if (h <= 0)
1680  return QPixmap();
1681 
1682  qreal factor = (qreal) h / height();
1683  QTransform wm = QTransform::fromScale(factor, factor);
1684  return transformed(wm, mode);
1685 }
double qreal
Definition: qglobal.h:1193
QPixmap()
Constructs a null pixmap.
Definition: qpixmap.cpp:174
QPixmap transformed(const QMatrix &, Qt::TransformationMode mode=Qt::FastTransformation) const
This convenience function loads the matrix into a QTransform and calls the overloaded function...
Definition: qpixmap.cpp:1723
Q_CORE_EXPORT void qWarning(const char *,...)
int height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
static QTransform fromScale(qreal dx, qreal dy)
Creates a matrix which corresponds to a scaling of sx horizontally and sy vertically.
Definition: qtransform.cpp:528
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
QPixmap copy(int x, int y, int width, int height) const
Returns a deep copy of the subset of the pixmap that is specified by the rectangle QRect( x...
Definition: qpixmap.h:302
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ scaledToWidth()

QPixmap QPixmap::scaledToWidth ( 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(), {QPixmap::Pixmap Transformations}{Pixmap Transformations}

Definition at line 1642 of file qpixmap.cpp.

Referenced by QUrlModel::setUrl().

1643 {
1644  if (isNull()) {
1645  qWarning("QPixmap::scaleWidth: Pixmap is a null pixmap");
1646  return copy();
1647  }
1648  if (w <= 0)
1649  return QPixmap();
1650 
1651  qreal factor = (qreal) w / width();
1652  QTransform wm = QTransform::fromScale(factor, factor);
1653  return transformed(wm, mode);
1654 }
double qreal
Definition: qglobal.h:1193
QPixmap()
Constructs a null pixmap.
Definition: qpixmap.cpp:174
int width() const
Returns the width of the pixmap.
Definition: qpixmap.cpp:630
QPixmap transformed(const QMatrix &, Qt::TransformationMode mode=Qt::FastTransformation) const
This convenience function loads the matrix into a QTransform and calls the overloaded function...
Definition: qpixmap.cpp:1723
Q_CORE_EXPORT void qWarning(const char *,...)
static QTransform fromScale(qreal dx, qreal dy)
Creates a matrix which corresponds to a scaling of sx horizontally and sy vertically.
Definition: qtransform.cpp:528
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
QPixmap copy(int x, int y, int width, int height) const
Returns a deep copy of the subset of the pixmap that is specified by the rectangle QRect( x...
Definition: qpixmap.h:302
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ scroll() [1/2]

void QPixmap::scroll ( int  dx,
int  dy,
int  x,
int  y,
int  width,
int  height,
QRegion exposed = 0 
)
inline
Since
4.6

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

See also
QWidget::scroll(), QGraphicsItem::scroll()

Definition at line 307 of file qpixmap.h.

Referenced by QGraphicsItem::scroll().

308 {
309  scroll(dx, dy, QRect(ax, ay, awidth, aheight), exposed);
310 }
void scroll(int dx, int dy, int x, int y, int width, int height, QRegion *exposed=0)
Definition: qpixmap.h:307
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ scroll() [2/2]

void QPixmap::scroll ( int  dx,
int  dy,
const QRect rect,
QRegion exposed = 0 
)

Scrolls the area rect of this pixmap by (dx, dy).

Since
4.6

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.

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

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

See also
QWidget::scroll(), QGraphicsItem::scroll()

Definition at line 434 of file qpixmap.cpp.

435 {
436  if (isNull() || (dx == 0 && dy == 0))
437  return;
438  QRect dest = rect & this->rect();
439  QRect src = dest.translated(-dx, -dy) & dest;
440  if (src.isEmpty()) {
441  if (exposed)
442  *exposed += dest;
443  return;
444  }
445 
446  detach();
447 
448  if (!data->scroll(dx, dy, src)) {
449  // Fallback
450  QPixmap pix = *this;
451  QPainter painter(&pix);
452  painter.setCompositionMode(QPainter::CompositionMode_Source);
453  painter.drawPixmap(src.translated(dx, dy), *this, src);
454  painter.end();
455  *this = pix;
456  }
457 
458  if (exposed) {
459  *exposed += dest;
460  *exposed -= src.translated(dx, dy);
461  }
462 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
void detach()
Detaches the pixmap from shared pixmap data.
Definition: qpixmap.cpp:2128
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
QRect translated(int dx, int dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:328
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QRect rect() const
Returns the pixmap&#39;s enclosing rectangle.
Definition: qpixmap.cpp:676
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
virtual bool scroll(int dx, int dy, const QRect &rect)

◆ serialNumber()

int QPixmap::serialNumber ( ) const

Returns a number that identifies the contents of this QPixmap object.

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.

Definition at line 1122 of file qpixmap.cpp.

1123 {
1124  if (isNull())
1125  return 0;
1126  return data->serialNumber();
1127 }
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
int serialNumber() const
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615

◆ setAlphaChannel()

void QPixmap::setAlphaChannel ( const QPixmap alphaChannel)

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(), {QPixmap::Pixmap Transformations}{Pixmap Transformations}

Definition at line 1999 of file qpixmap.cpp.

2000 {
2001  if (alphaChannel.isNull())
2002  return;
2003 
2004  if (paintingActive()) {
2005  qWarning("QPixmap::setAlphaChannel: "
2006  "Cannot set alpha channel while pixmap is being painted on");
2007  return;
2008  }
2009 
2010  if (width() != alphaChannel.width() && height() != alphaChannel.height()) {
2011  qWarning("QPixmap::setAlphaChannel: "
2012  "The pixmap and the alpha channel pixmap must have the same size");
2013  return;
2014  }
2015 
2016  detach();
2017  data->setAlphaChannel(alphaChannel);
2018 }
int width() const
Returns the width of the pixmap.
Definition: qpixmap.cpp:630
void detach()
Detaches the pixmap from shared pixmap data.
Definition: qpixmap.cpp:2128
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
bool paintingActive() const
Definition: qpaintdevice.h:170
Q_CORE_EXPORT void qWarning(const char *,...)
int height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
virtual void setAlphaChannel(const QPixmap &alphaChannel)
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615

◆ setMask()

void QPixmap::setMask ( 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(), {QPixmap::Pixmap Transformations}{Pixmap Transformations}, QBitmap

Definition at line 822 of file qpixmap.cpp.

Referenced by QWindowsStyle::drawComplexControl(), QCursor::QCursor(), qDrawPlainRect(), and QX11PixmapData::transformed().

823 {
824  if (paintingActive()) {
825  qWarning("QPixmap::setMask: Cannot set mask while pixmap is being painted on");
826  return;
827  }
828 
829  if (!mask.isNull() && mask.size() != size()) {
830  qWarning("QPixmap::setMask() mask size differs from pixmap size");
831  return;
832  }
833 
834  if (isNull())
835  return;
836 
837  if (static_cast<const QPixmap &>(mask).data == data) // trying to selfmask
838  return;
839 
840  detach();
841  data->setMask(mask);
842 }
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
void detach()
Detaches the pixmap from shared pixmap data.
Definition: qpixmap.cpp:2128
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
bool paintingActive() const
Definition: qpaintdevice.h:170
Q_CORE_EXPORT void qWarning(const char *,...)
virtual void setMask(const QBitmap &mask)
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615

◆ size()

QSize QPixmap::size ( ) const

Returns the size of the pixmap.

See also
width(), height(), {QPixmap::Pixmap Information}{Pixmap Information}

Definition at line 661 of file qpixmap.cpp.

Referenced by QLabelPrivate::_q_movieUpdated(), QSvgIconEngine::actualSize(), QPixmapIconEngine::addFile(), QPixmapIconEngine::addPixmap(), QPixmapIconEngine::bestMatch(), bestSizeMatch(), QPaintBuffer::commandDescription(), QMdi::ControlLabel::ControlLabel(), create32BitCursor(), depth(), QPixmapDropShadowFilter::draw(), QRenderRule::drawBackgroundImage(), QRenderRule::drawBorderImage(), QStyleHelper::drawBorderPixmap(), QCommonStyle::drawControl(), QMacStyle::drawControl(), QItemDelegate::drawDecoration(), QPaintEngine::drawImage(), QGraphicsScenePrivate::drawItemHelper(), QStyle::drawItemPixmap(), QBlitterPaintEngine::drawPixmap(), QDirectFBPaintEngine::drawPixmap(), QWin32PrintEngine::drawPixmap(), QGL2PaintEngineEx::drawPixmap(), QOpenGLPaintEngine::drawPixmap(), QRasterPaintEngine::drawPixmap(), QPaintEngineEx::drawPixmap(), QPaintBufferEngine::drawPixmap(), QGL2PaintEngineEx::drawPixmapFragments(), QDirectFBPaintEngine::drawTiledPixmap(), QOpenGLPaintEngine::drawTiledPixmap(), QRasterPaintEngine::drawTiledPixmap(), QX11GLWindowSurface::flush(), QAccessibleDisplay::imageSize(), QStyledItemDelegate::initStyleOption(), QMoviePrivate::next(), QBitmap::operator=(), QItemDelegate::paint(), QGtkPainter::paintBox(), QGtkPainter::paintBoxGap(), QSvgIconEngine::pixmap(), QPixmapIconEngine::pixmap(), pixmapsAreEqual(), QGLPixmapConvolutionFilter::processGL(), QCursor::QCursor(), scaled(), QMacWindowSurface::scroll(), QCursorData::setBitmap(), QX11GLWindowSurface::setGeometry(), QMacWindowSurface::setGeometry(), QX11WindowSurface::setGeometry(), QRasterPixmapData::setMask(), QPixmapData::setMask(), setMask(), QCursor::setPos(), QWizardHeader::setup(), QMdi::ControlLabel::sizeHint(), toWinHICON(), QOpenGLPaintEnginePrivate::updateFragmentProgramData(), and QPixmapIconEngine::virtual_hook().

662 {
663  return data ? QSize(data->width(), data->height()) : QSize(0, 0);
664 }
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
int width() const
int height() const
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ swap()

void QPixmap::swap ( QPixmap other)
inline

Swaps pixmap other with this pixmap.

Since
4.8

This operation is very fast and never fails.

Definition at line 90 of file qpixmap.h.

Referenced by QBitmap::swap().

90 { qSwap(data, other.data); }
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181

◆ toImage()

QImage QPixmap::toImage ( ) 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(), {QImage::Image Formats}{Image Formats}

Definition at line 542 of file qpixmap.cpp.

Referenced by QPdfEnginePrivate::addBrushPattern(), QFontEngineXLFD::addOutlineToPath(), QFontEngineXLFD::alphaMapForGlyph(), QPlatformSoftwareCursor::changeCursor(), create32BitCursor(), QXlibCursor::createCursorBitmap(), createHeuristicMask(), createMaskFromColor(), darkenPixmap(), QWSDisplay::defineCursor(), doImageIO(), QPixmapConvolutionFilter::draw(), QPixmapBlurFilter::draw(), QPixmapColorizeFilter::draw(), QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(), QMacStylePrivate::drawColorlessButton(), QCommonStyle::drawControl(), QWindowsStyle::drawControl(), QMotifStyle::drawControl(), QVGCompositionHelper::drawCursorPixmap(), QPdfEngine::drawPixmap(), QOpenGLPaintEngine::drawPixmap(), QSvgPaintEngine::drawPixmap(), QRasterPaintEngine::drawPixmap(), QOpenGLPaintEngine::drawTiledPixmap(), QRasterPaintEngine::drawTiledPixmap(), QWindowsMobileStyle::generatedIconPixmap(), QCommonStyle::generatedIconPixmap(), QMacStyle::generatedIconPixmap(), QMoviePrivate::next(), operator<<(), QBitmap::operator=(), pixmapsAreEqual(), QGLPixmapBlurFilter::processGL(), QGLPixmapDropShadowFilter::processGL(), qBrushDark(), qBrushLight(), qBrushSetAlphaF(), QTest::qCompare(), QCursor::QCursor(), qstring_to_xtp(), qt_bitmapToRegion(), qt_createIconMask(), qt_mac_create_iconref(), qt_toRasterPixmap(), qt_toX11Pixmap(), QAlphaWidget::run(), QItemDelegate::selected(), QRasterPixmapData::setAlphaChannel(), QX11PixmapData::setAlphaChannel(), QVolatileImage::setAlphaChannel(), QPixmapData::setAlphaChannel(), QRasterPixmapData::setMask(), QPixmapData::setMask(), QCursor::setPos(), QSystemTrayIconPrivate::showMessage_sys(), QMacStyle::styleHint(), QX11PixmapData::toImage(), toWinHBITMAP(), QX11Data::xdndMimeConvertToFormat(), and QX11Data::xdndMimeDataForAtom().

543 {
544  if (isNull())
545  return QImage();
546 
547  return data->toImage();
548 }
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
virtual QImage toImage() const =0
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615

◆ toMacCGImageRef()

CGImageRef QPixmap::toMacCGImageRef ( ) const

Creates a CGImageRef equivalent to the QPixmap.

Since
4.2

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()

Definition at line 1254 of file qpixmap_mac.cpp.

Referenced by QCoreGraphicsPaintEngine::drawPixmap(), QMacWindowSurface::flush(), qt_mac_create_nsimage(), and QMacWindowSurface::scroll().

1255 {
1256  return (CGImageRef)macCGHandle();
1257 }
struct CGImage * CGImageRef

◆ toWinHBITMAP()

HBITMAP QPixmap::toWinHBITMAP ( HBitmapFormat  format = NoAlpha) const

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

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

Warning
This function is only available on Windows.
See also
fromWinHBITMAP(), {QPixmap::Pixmap Conversion}{Pixmap Conversion}

Definition at line 122 of file qpixmap_win.cpp.

Referenced by create32BitCursor(), QAxServerBase::Draw(), QWin32PrintEngine::drawPixmap(), QWin32PrintEngine::drawTiledPixmap(), QAxHostWidget::paintEvent(), QPixmapToIPicture(), and toWinHICON().

123 {
124  if (isNull())
125  return 0;
126 
127  HBITMAP bitmap = 0;
129  QRasterPixmapData* d = static_cast<QRasterPixmapData*>(data.data());
130  int w = d->image.width();
131  int h = d->image.height();
132 
133  HDC display_dc = GetDC(0);
134 
135  // Define the header
136  BITMAPINFO bmi;
137  memset(&bmi, 0, sizeof(bmi));
138  bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
139  bmi.bmiHeader.biWidth = w;
140  bmi.bmiHeader.biHeight = -h;
141  bmi.bmiHeader.biPlanes = 1;
142  bmi.bmiHeader.biBitCount = 32;
143  bmi.bmiHeader.biCompression = BI_RGB;
144  bmi.bmiHeader.biSizeImage = w * h * 4;
145 
146  // Create the pixmap
147  uchar *pixels = 0;
148  bitmap = CreateDIBSection(display_dc, &bmi, DIB_RGB_COLORS, (void **) &pixels, 0, 0);
149  ReleaseDC(0, display_dc);
150  if (!bitmap) {
151  qErrnoWarning("QPixmap::toWinHBITMAP(), failed to create dibsection");
152  return 0;
153  }
154  if (!pixels) {
155  qErrnoWarning("QPixmap::toWinHBITMAP(), did not allocate pixel data");
156  return 0;
157  }
158 
159  // Copy over the data
161  if (format == NoAlpha)
162  imageFormat = QImage::Format_RGB32;
163  else if (format == PremultipliedAlpha)
165  const QImage image = d->image.convertToFormat(imageFormat);
166  int bytes_per_line = w * 4;
167  for (int y=0; y<h; ++y)
168  memcpy(pixels + y * bytes_per_line, image.scanLine(y), bytes_per_line);
169 
170  } else {
171  QPixmapData *data = new QRasterPixmapData(depth() == 1 ?
173  data->fromImage(toImage(), Qt::AutoColor);
174  return QPixmap(data).toWinHBITMAP(format);
175  }
176  return bitmap;
177 }
double d
Definition: qnumeric_p.h:62
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
Format
The following image formats are available in Qt.
Definition: qimage.h:91
QPixmap()
Constructs a null pixmap.
Definition: qpixmap.cpp:174
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
int depth() const
Returns the depth of the pixmap.
Definition: qpixmap.cpp:695
unsigned char uchar
Definition: qglobal.h:994
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
virtual void fromImage(const QImage &image, Qt::ImageConversionFlags flags)=0
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
ClassId classId() const
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

◆ toWinHICON()

HICON QPixmap::toWinHICON ( ) const

Returns the HICON handle.

Since
4.6

Win32 only: Creates a HICON equivalent to the QPixmap.

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

Warning
This function is only available on Windows.
See also
fromWinHICON(), {QPixmap::Pixmap Conversion}{Pixmap Conversion}

Definition at line 257 of file qpixmap_win.cpp.

Referenced by QSystemTrayIconSys::createIcon(), QVistaHelper::drawTitleBar(), QSystemTrayIconSys::findTrayGeometry(), and qt_createIcon().

258 {
259  QBitmap maskBitmap = mask();
260  if (maskBitmap.isNull()) {
261  maskBitmap= QBitmap(size());
262  maskBitmap.fill(Qt::color1);
263  }
264 
265  ICONINFO ii;
266  ii.fIcon = true;
267  ii.hbmMask = qt_createIconMask(maskBitmap);
268  ii.hbmColor = toWinHBITMAP(QPixmap::Alpha);
269  ii.xHotspot = 0;
270  ii.yHotspot = 0;
271 
272  HICON hIcon = CreateIconIndirect(&ii);
273 
274  DeleteObject(ii.hbmColor);
275  DeleteObject(ii.hbmMask);
276 
277  return hIcon;
278 }
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
The QBitmap class provides monochrome (1-bit depth) pixmaps.
Definition: qbitmap.h:55
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Definition: qpixmap.cpp:1080
HBITMAP toWinHBITMAP(HBitmapFormat format=NoAlpha) const
It is the caller&#39;s responsibility to free the HBITMAP data after use.
QBitmap mask() const
Extracts a bitmap mask from the pixmap&#39;s alpha channel.
Definition: qpixmap.cpp:2077
HBITMAP qt_createIconMask(const QBitmap &bitmap)
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
friend class QBitmap
Definition: qpixmap.h:279

◆ transformed() [1/2]

QPixmap QPixmap::transformed ( const QMatrix matrix,
Qt::TransformationMode  mode = Qt::FastTransformation 
) const

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 1723 of file qpixmap.cpp.

Referenced by QBitmap::clear(), QWin32PrintEngine::drawPixmap(), scaled(), scaledToHeight(), scaledToWidth(), and QBitmap::transformed().

1724 {
1725  return transformed(QTransform(matrix), mode);
1726 }
QPixmap transformed(const QMatrix &, Qt::TransformationMode mode=Qt::FastTransformation) const
This convenience function loads the matrix into a QTransform and calls the overloaded function...
Definition: qpixmap.cpp:1723
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ transformed() [2/2]

QPixmap QPixmap::transformed ( 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(), {QPixmap::Pixmap Transformations}{Pixmap Transformations}

Definition at line 1705 of file qpixmap.cpp.

1707 {
1708  if (isNull() || transform.type() <= QTransform::TxTranslate)
1709  return *this;
1710 
1711  return data->transformed(transform, mode);
1712 }
virtual QPixmap transformed(const QTransform &matrix, Qt::TransformationMode mode) const
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
TransformationType type() const
Returns the transformation type of this matrix.
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615

◆ trueMatrix() [1/2]

QMatrix QPixmap::trueMatrix ( const QMatrix m,
int  w,
int  h 
)
static

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.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 584 of file qpixmap.cpp.

Referenced by QWin32PrintEngine::drawPixmap(), QMacPixmapData::macCreatePixels(), and QX11PixmapData::transformed().

585 {
586  return trueMatrix(QTransform(m), w, h).toAffine();
587 }
static QMatrix trueMatrix(const QMatrix &m, int w, int h)
This convenience function loads the matrix m into a QTransform and calls the overloaded function with...
Definition: qpixmap.cpp:584
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ trueMatrix() [2/2]

QTransform QPixmap::trueMatrix ( 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(), {QPixmap::Pixmap Transformations}{Pixmap Transformations}

Definition at line 569 of file qpixmap.cpp.

570 {
571  return QImage::trueMatrix(m, w, h);
572 }
static QMatrix trueMatrix(const QMatrix &, int w, int h)
Returns the actual matrix used for transforming an image with the given width, height and matrix...
Definition: qimage.cpp:4680

◆ width()

int QPixmap::width ( ) const

Returns the width of the pixmap.

See also
size(), {QPixmap::Pixmap Information}{Pixmap Information}

Definition at line 630 of file qpixmap.cpp.

Referenced by QX11WindowSurface::beginPaint(), QX11PixmapData::bitmap_to_mask(), copy(), QXlibCursor::createCursorBitmap(), QOleDropSource::createCursors(), QWSDisplay::defineCursor(), depth(), QDragManager::drag(), QAxServerBase::Draw(), QTreeViewPrivate::drawAnimatedOperation(), QRenderRule::drawBackgroundImage(), QMacStylePrivate::drawCombobox(), QCommonStyle::drawControl(), QWindowsCEStyle::drawControl(), QWindowsVistaStyle::drawControl(), QPlastiqueStyle::drawControl(), QWindowsMobileStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsXPStyle::drawControl(), QWindowsStyle::drawControl(), QGtkStyle::drawControl(), QMotifStyle::drawControl(), QMacStyle::drawControl(), QStyleSheetStyle::drawControl(), QDeclarativeTextPrivate::drawOutline(), QWin32PrintEngine::drawPixmap(), QCoreGraphicsPaintEngine::drawPixmap(), QGL2PaintEngineEx::drawPixmap(), QOpenGLPaintEngine::drawPixmap(), QPainter::drawPixmap(), QMacStylePrivate::drawTableHeader(), QPSPrintEngine::drawTiledPixmap(), QWin32PrintEngine::drawTiledPixmap(), QX11PaintEngine::drawTiledPixmap(), QOpenGLPaintEngine::drawTiledPixmap(), QPaintEngine::drawTiledPixmap(), QPainter::drawTiledPixmap(), QBlitterPaintEngine::fillRect(), QMacStylePrivate::generateBackgroundPattern(), getPixmapSize(), QMeeGoLivePixmapData::initializeThroughEGLImage(), QPixmapCache::insert(), QGLBlurTextureCache::insertBlurTextureInfo(), QStyle::itemPixmapRect(), QX11PixmapData::mask_to_bitmap(), menuItemEntry(), QColorWell::mouseMoveEvent(), QColorShowLabel::mouseMoveEvent(), QGtkPainter::paintBox(), QGtkPainter::paintBoxGap(), QAxHostWidget::paintEvent(), QColorLuminancePicker::paintEvent(), QGLOverlayWidget::paintGL(), QMacStyle::polish(), QCursor::QCursor(), qDrawPlainRect(), qt_draw_tile(), qt_fill_tile(), qt_mac_draw_pattern(), QPixmapCache::replace(), scaled(), scaledToWidth(), setAlphaChannel(), QCursorData::setBitmap(), QShapedPixmapWidget::setPixmap(), QMacStyle::standardIconImplementation(), QGL2PaintEngineExPrivate::updateBrushTexture(), QGL2PaintEngineExPrivate::updateBrushUniforms(), QGLContextPrivate::updateFormatVersion(), QGLContext::updatePaintDevice(), QGraphicsPixmapItemPrivate::updateShape(), and QDeclarativePixmap::width().

631 {
632  return data ? data->width() : 0;
633 }
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
int width() const

Friends and Related Functions

◆ operator<<()

QDataStream & operator<< ( QDataStream stream,
const QPixmap pixmap 
)
related

Writes the given pixmap to the given stream as a PNG image.

Note that writing the stream to a file will not produce a valid image file.

See also
QPixmap::save(), {Serializing Qt Data Types}

Definition at line 1430 of file qpixmap.cpp.

1431 {
1432  return stream << pixmap.toImage();
1433 }
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542

◆ operator>>

QDataStream & operator>> ( QDataStream stream,
QPixmap pixmap 
)
friend

Reads an image from the given stream into the given pixmap.

See also
QPixmap::load(), {Serializing Qt Data Types}

Definition at line 1446 of file qpixmap.cpp.

1447 {
1448  QImage image;
1449  stream >> image;
1450 
1451  if (image.isNull()) {
1452  pixmap = QPixmap();
1453  } else if (image.depth() == 1) {
1454  pixmap = QBitmap::fromImage(image);
1455  } else {
1456  pixmap = QPixmap::fromImage(image);
1457  }
1458  return stream;
1459 }
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition: qpixmap.cpp:2197
QPixmap()
Constructs a null pixmap.
Definition: qpixmap.cpp:174
static FILE * stream
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static QBitmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Returns a copy of the given image converted to a bitmap using the specified image conversion flags...
Definition: qbitmap.cpp:281

◆ QBitmap

friend class QBitmap
friend

Definition at line 279 of file qpixmap.h.

Referenced by QBitmap::clear(), mask(), and toWinHICON().

◆ QCoreGraphicsPaintEngine

Definition at line 284 of file qpixmap.h.

◆ QGLWidget

friend class QGLWidget
friend

Definition at line 282 of file qpixmap.h.

◆ QMacPixmapData

friend class QMacPixmapData
friend

Definition at line 277 of file qpixmap.h.

◆ QPaintDevice

friend class QPaintDevice
friend

Definition at line 280 of file qpixmap.h.

◆ QPainter

friend class QPainter
friend

Definition at line 281 of file qpixmap.h.

◆ QPixmapData

friend class QPixmapData
friend

Definition at line 275 of file qpixmap.h.

◆ QRasterBuffer

friend class QRasterBuffer
friend

Definition at line 286 of file qpixmap.h.

◆ QSymbianRasterPixmapData

friend class QSymbianRasterPixmapData
friend

Definition at line 278 of file qpixmap.h.

◆ qt_mac_cg_context

CGContextRef qt_mac_cg_context ( const QPaintDevice )
friend

Returns the CoreGraphics CGContextRef of the paint device.

Warning
This function is not part of the public interface.

0 is returned if it can't be obtained. It is the caller's responsiblity to CGContextRelease the context when finished using it.

Warning
This function is only available on Mac OS X.

Definition at line 118 of file qpaintdevice_mac.cpp.

119 {
120  if (pdev->devType() == QInternal::Pixmap) {
121  const QPixmap *pm = static_cast<const QPixmap*>(pdev);
123  uint flags = kCGImageAlphaPremultipliedFirst;
124 #ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version
125  flags |= kCGBitmapByteOrder32Host;
126 #endif
127  CGContextRef ret = 0;
128 
129  // It would make sense to put this into a mac #ifdef'ed
130  // virtual function in the QPixmapData at some point
131  if (pm->data->classId() == QPixmapData::MacClass) {
132  const QMacPixmapData *pmData = static_cast<const QMacPixmapData*>(pm->data.data());
133  ret = CGBitmapContextCreate(pmData->pixels, pmData->w, pmData->h,
134  8, pmData->bytesPerRow, colorspace,
135  flags);
136  if(!ret)
137  qWarning("QPaintDevice: Unable to create context for pixmap (%d/%d/%d)",
138  pmData->w, pmData->h, (pmData->bytesPerRow * pmData->h));
139  } else if (pm->data->classId() == QPixmapData::RasterClass) {
140  QImage *image = pm->data->buffer();
141  ret = CGBitmapContextCreate(image->bits(), image->width(), image->height(),
142  8, image->bytesPerLine(), colorspace, flags);
143  }
144 
145  CGContextTranslateCTM(ret, 0, pm->height());
146  CGContextScaleCTM(ret, 1, -1);
147  return ret;
148  } else if (pdev->devType() == QInternal::Widget) {
149  CGContextRef ret = static_cast<CGContextRef>(static_cast<const QWidget *>(pdev)->macCGHandle());
150  CGContextRetain(ret);
151  return ret;
152  } else if (pdev->devType() == QInternal::MacQuartz) {
153  return static_cast<const QMacQuartzPaintDevice *>(pdev)->cgContext();
154  }
155  return 0;
156 }
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
CGColorSpaceRef qt_mac_colorSpaceForDeviceType(const QPaintDevice *pdev)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
virtual int devType() const
Definition: qpaintdevice.h:167
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
unsigned int uint
Definition: qglobal.h:996
ClassId classId() const
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
struct CGColorSpace * CGColorSpaceRef
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
virtual QImage * buffer()
int height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
struct CGContext * CGContextRef
quint32 * pixels

◆ qt_mac_create_iconref

IconRef qt_mac_create_iconref ( const QPixmap )
friend

Definition at line 1109 of file qpixmap_mac.cpp.

1110 {
1111  if (px.isNull())
1112  return 0;
1113 
1114  //create icon
1115  IconFamilyHandle iconFamily = reinterpret_cast<IconFamilyHandle>(NewHandle(0));
1116  //create data
1117  {
1118  struct {
1119  OSType mac_type;
1120  int width, height, depth;
1121  bool mask;
1122  } images[] = {
1123  { kThumbnail32BitData, 128, 128, 32, false },
1124  { kThumbnail8BitMask, 128, 128, 8, true },
1125  { 0, 0, 0, 0, false } //end marker
1126  };
1127  for(int i = 0; images[i].mac_type; i++) {
1128  //get QPixmap data
1129  QImage scaled_px = px.toImage().scaled(images[i].width, images[i].height);
1130 
1131  quint32 *sptr = (quint32 *) scaled_px.bits();
1132  quint32 *srow;
1133  uint sbpr = scaled_px.bytesPerLine();
1134 
1135  //get Handle data
1136  const int dbpr = images[i].width * (images[i].depth/8);
1137  Handle hdl = NewHandle(dbpr*images[i].height);
1138  if(!sptr) { //handle null pixmap
1139  memset((*hdl), '\0', dbpr*images[i].height);
1140  } else if(images[i].mask) {
1141  if(images[i].mac_type == kThumbnail8BitMask) {
1142  for(int y = 0, hindex = 0; y < images[i].height; ++y) {
1143  srow = sptr + (y * (sbpr/4));
1144  for(int x = 0; x < images[i].width; ++x)
1145  *((*hdl)+(hindex++)) = qAlpha(*(srow+x));
1146  }
1147  }
1148  } else {
1149  char *dest = (*hdl);
1150 #if defined(__i386__)
1151  if(images[i].depth == 32) {
1152  for(int y = 0; y < images[i].height; ++y) {
1153  uint *source = (uint*)((const uchar*)sptr+(sbpr*y));
1154  for(int x = 0; x < images[i].width; ++x, dest += 4)
1155  *((uint*)dest) = CFSwapInt32(*(source + x));
1156  }
1157  } else
1158 #endif
1159  {
1160  for(int y = 0; y < images[i].height; ++y)
1161  memcpy(dest+(y*dbpr), ((const uchar*)sptr+(sbpr*y)), dbpr);
1162  }
1163  }
1164 
1165  //set the family data to the Handle
1166  OSStatus set = SetIconFamilyData(iconFamily, images[i].mac_type, hdl);
1167  if(set != noErr)
1168  qWarning("%s: %d -- Unable to create icon data[%d]!! %ld",
1169  __FILE__, __LINE__, i, long(set));
1170  DisposeHandle(hdl);
1171  }
1172  }
1173 
1174  //acquire and cleanup
1175  IconRef ret;
1176  static int counter = 0;
1177  const OSType kQtCreator = 'CUTE';
1178  RegisterIconRefFromIconFamily(kQtCreator, (OSType)counter, iconFamily, &ret);
1179  AcquireIconRef(ret);
1180  UnregisterIconRef(kQtCreator, (OSType)counter);
1181  DisposeHandle(reinterpret_cast<Handle>(iconFamily));
1182  counter++;
1183  return ret;
1184 
1185 }
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
int width() const
Returns the width of the pixmap.
Definition: qpixmap.cpp:630
Q_GUI_EXPORT_INLINE int qAlpha(QRgb rgb)
Definition: qrgb.h:66
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
int depth() const
Returns the depth of the pixmap.
Definition: qpixmap.cpp:695
unsigned char uchar
Definition: qglobal.h:994
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
unsigned int uint
Definition: qglobal.h:996
signed long OSStatus
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
QBitmap mask() const
Extracts a bitmap mask from the pixmap&#39;s alpha channel.
Definition: qpixmap.cpp:2077
unsigned int quint32
Definition: qglobal.h:938
int height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
QImage scaled(int w, int h, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
Definition: qimage.h:232
struct OpaqueIconRef * IconRef

◆ qt_mac_create_imagemask

CGImageRef qt_mac_create_imagemask ( const QPixmap ,
const QRectF  
)
friend

Definition at line 1077 of file qpixmap_mac.cpp.

1078 {
1079  QMacPixmapData *px = static_cast<QMacPixmapData*>(pixmap.data.data());
1080  if (px->cg_mask) {
1081  if (px->cg_mask_rect == sr) {
1082  CGImageRetain(px->cg_mask); //reference for the caller
1083  return px->cg_mask;
1084  }
1085  CGImageRelease(px->cg_mask);
1086  px->cg_mask = 0;
1087  }
1088 
1089  const int sx = qRound(sr.x()), sy = qRound(sr.y()), sw = qRound(sr.width()), sh = qRound(sr.height());
1090  const int sbpr = px->bytesPerRow;
1091  const uint nbytes = sw * sh;
1092  // alpha is always 255 for bitmaps, ignore it in this case.
1093  const quint32 mask = px->depth() == 1 ? 0x00ffffff : 0xffffffff;
1094  quint8 *dptr = static_cast<quint8 *>(malloc(nbytes));
1095  quint32 *sptr = px->pixels, *srow;
1096  for(int y = sy, offset=0; y < sh; ++y) {
1097  srow = sptr + (y * (sbpr / 4));
1098  for(int x = sx; x < sw; ++x)
1099  *(dptr+(offset++)) = (*(srow+x) & mask) ? 255 : 0;
1100  }
1101  QCFType<CGDataProviderRef> provider = CGDataProviderCreateWithData(0, dptr, nbytes, qt_mac_cgimage_data_free);
1102  px->cg_mask = CGImageMaskCreate(sw, sh, 8, 8, nbytes / sh, provider, 0, 0);
1103  px->cg_mask_rect = sr;
1104  CGImageRetain(px->cg_mask); //reference for the caller
1105  return px->cg_mask;
1106 }
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
unsigned char quint8
Definition: qglobal.h:934
CGImageRef cg_mask
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
unsigned int uint
Definition: qglobal.h:996
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
int depth() const
QBitmap mask() const
Extracts a bitmap mask from the pixmap&#39;s alpha channel.
Definition: qpixmap.cpp:2077
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
void qt_mac_cgimage_data_free(void *info, const void *memoryToFree, size_t)
Definition: qpixmap_mac.cpp:91
unsigned int quint32
Definition: qglobal.h:938
quint32 * pixels
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ qt_mac_pixmap_get_base

quint32* qt_mac_pixmap_get_base ( const QPixmap )
friend

Definition at line 75 of file qpixmap_mac.cpp.

76 {
78  return reinterpret_cast<quint32 *>(static_cast<QRasterPixmapData*>(pix->data.data())->buffer()->bits());
79  else
80  return static_cast<QMacPixmapData*>(pix->data.data())->pixels;
81 }
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
static QString graphics_system_name
unsigned int quint32
Definition: qglobal.h:938

◆ qt_mac_pixmap_get_bytes_per_line

int qt_mac_pixmap_get_bytes_per_line ( const QPixmap )
friend

Definition at line 83 of file qpixmap_mac.cpp.

84 {
86  return static_cast<QRasterPixmapData*>(pix->data.data())->buffer()->bytesPerLine();
87  else
88  return static_cast<QMacPixmapData*>(pix->data.data())->bytesPerRow;
89 }
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
static QString graphics_system_name

◆ qt_pixmap_id

Q_GUI_EXPORT qint64 qt_pixmap_id ( const QPixmap pixmap)
friend

Definition at line 94 of file qpixmap.cpp.

95 {
96  return pixmap.cacheKey();
97 }
qint64 cacheKey() const
Returns a number that identifies this QPixmap.
Definition: qpixmap.cpp:1136

◆ QWidgetPrivate

friend class QWidgetPrivate
friend

Definition at line 285 of file qpixmap.h.

◆ QX11PaintEngine

friend class QX11PaintEngine
friend

Definition at line 283 of file qpixmap.h.

◆ QX11PixmapData

friend class QX11PixmapData
friend

Definition at line 276 of file qpixmap.h.

Properties

◆ data

QExplicitlySharedDataPointer<QPixmapData> QPixmap::data
private

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