QPixmap(3qt)
QPixmap(3qt) β yep bestie, that's the manual page we're standing in. Part 1 of 4. Buckle up. π
β¨ NAME β¨
QPixmap β off-screen, pixel-based paint device. That's the whole vibe. πΌοΈ
πΈ SYNOPSIS πΈ
#include <qpixmap.h>
Inherits QPaintDevice and Qt.
Inherited by QBitmap and QCanvasPixmap.
π Public Members
Like, here's the whole roster. Every single one. No skips, no cuts. π
enum ColorMode { Auto, Color, Mono }β the color mode enum, more on it belowenum Optimization { DefaultOptim, NoOptim, MemoryOptim = NoOptim, NormalOptim, BestOptim }β the optimization enum, also belowQPixmap ()β the "make me a null one" constructorQPixmap ( const QImage & image )β build a pixmap out of aQImageQPixmap ( int w, int h, int depth = -1, Optimization optimization = DefaultOptim )β w, h, depth, optimizationQPixmap ( const QSize & size, int depth = -1, Optimization optimization = DefaultOptim )β same but with aQSizeQPixmap ( const QString & fileName, const char * format = 0, ColorMode mode = Auto )β straight from a fileQPixmap ( const QString & fileName, const char * format, int conversion_flags )β file, with conversion flags this timeQPixmap ( const char * xpm[] )β from an XPM arrayQPixmap ( const QByteArray & img_data )β from raw image data in aQByteArrayQPixmap ( const QPixmap & pixmap )β copy constructor, she's cheap because copy-on-write~QPixmap ()β destructor, bye πQPixmap & operator= ( const QPixmap & pixmap )β assign a pixmapQPixmap & operator= ( const QImage & image )β assign an imagebool isNull () constβ is it null?int width () constβ how wideint height () constβ how tallQSize size () constβ the size as aQSizeQRect rect () constβ the enclosing rectangleint depth () constβ bits per pixel energyvoid fill ( const QColor & fillColor = Qt::white )β flood it with a colorvoid fill ( const QWidget * widget, int xofs, int yofs )β fill from a widget with offsetsvoid fill ( const QWidget * widget, const QPoint & ofs )β same, but the offset is aQPointvoid resize ( int w, int h )β resize by numbersvoid resize ( const QSize & size )β resize byQSizeconst QBitmap * mask () constβ hand me the maskvoid setMask ( const QBitmap & newmask )β set a new maskbool selfMask () constβ is the pixmap literally identical to its mask?bool hasAlpha () constβ alpha checkbool hasAlphaChannel () constβ alpha channel checkQBitmap createHeuristicMask ( bool clipTight = TRUE ) constβ heuristically guess a maskQPixmap xForm ( const QWMatrix & matrix ) constβ transformed copy of the pixmapQImage convertToImage () constβ pixmap to imagebool convertFromImage ( const QImage & image, ColorMode mode = Auto )β image to pixmapbool convertFromImage ( const QImage & img, int conversion_flags )β image to pixmap, flags versionbool load ( const QString & fileName, const char * format = 0, ColorMode mode = Auto )β load it upbool load ( const QString & fileName, const char * format, int conversion_flags )β load with conversion flagsbool loadFromData ( const uchar * buf, uint len, const char * format = 0, ColorMode mode = Auto )β load from a bufferbool loadFromData ( const uchar * buf, uint len, const char * format, int conversion_flags )β buffer + flagsbool loadFromData ( const QByteArray & buf, const char * format = 0, int conversion_flags = 0 )β buffer as aQByteArraybool save ( const QString & fileName, const char * format, int quality = -1 ) constβ save to a filebool save ( QIODevice * device, const char * format, int quality = -1 ) constβ save to a deviceint serialNumber () constβ the serial numberOptimization optimization () constβ what optimization is she onvoid setOptimization ( Optimization optimization )β set the optimizationvirtual void detach ()β detach (it's virtual, so you can override, iykyk)bool isQBitmap () constβ is it actually aQBitmap?
π¦ Static Public Members
int defaultDepth ()β the default depthQPixmap fromMimeSource ( const QString & abs_name )β pixmap out of a mime sourceQPixmap grabWindow ( WId window, int x = 0, int y = 0, int w = -1, int h = -1 )β grab a windowQPixmap grabWidget ( QWidget * widget, int x = 0, int y = 0, int w = -1, int h = -1 )β grab a widgetQWMatrix trueMatrix ( const QWMatrix & matrix, int w, int h )β the true matrixconst char * imageFormat ( const QString & fileName )β figure out the format from the filenameOptimization defaultOptimization ()β current default optimizationvoid setDefaultOptimization ( Optimization optimization )β set the default optimization
π§ Protected Members
QPixmap ( int w, int h, const uchar * bits, bool isXbitmap )β the protected constructorvirtual int metric ( int m ) constβ the metric function, virtual
π RELATED FUNCTION DOCUMENTATION π
QDataStream & operator<< ( QDataStream & s, const QPixmap & pixmap )
QDataStream & operator>> ( QDataStream & s, QPixmap & pixmap )
void copyBlt ( QPixmap * dst, int dx, int dy, const QPixmap * src, int sx, int sy, int sw, int sh )
π DESCRIPTION π
Okay so. The QPixmap class is an off-screen, pixel-based paint device. That's the one-liner and honestly it ate.
QPixmap is one of the two classes Qt hands you for dealing with images β the other one is QImage. And here's the tea: QPixmap is designed and optimized for drawing, while QImage is designed and optimized for I/O and for direct pixel access/manipulation. Different queens, different jobs. π
And yeah, there are (slow) functions to convert between QImage and QPixmap: convertToImage() and convertFromImage(). Slow. Noted. π
One super common use of QPixmap is making widgets update smoothly. Whenever something complex needs to be drawn, you can use a pixmap to get flicker-free drawing, like this:
- Create a pixmap with the same size as the widget.
- Fill the pixmap with the widget background color.
- Paint the pixmap.
bitBlt()the pixmap contents onto the widget.
Pixel data inside a pixmap is internal and is managed by the underlying window system. Which means pixels can only be accessed through QPainter functions, through bitBlt(), and by converting the QPixmap to a QImage. That's it. That's the whole list. No sneaking. π«
You can display a QPixmap on screen so easily with QLabel::setPixmap(). For example, all the QButton subclasses support pixmap use. Iconic behavior honestly.
The QPixmap class uses copy-on-write, so it is practical to pass QPixmap objects by value. Bestie you can just pass her around, she's fine. π«Ά
You can retrieve the width(), height(), depth() and size() of a pixmap. The enclosing rectangle is given by rect(). Pixmaps can be filled with fill() and resized with resize(). You can create and set a mask with createHeuristicMask() and setMask(). And use selfMask() to see if the pixmap is identical to its mask. Chef's kiss. π
In addition to loading a pixmap from file using load() you can also loadFromData(). You can control optimization with setOptimization() and obtain a transformed version of the pixmap using xForm()
β οΈ Note regarding Windows 95 and 98: on Windows 9x the system crashes if you create more than about 1000 pixmaps, independent of the size of the pixmaps or installed RAM. Windows NT-systems (including 2000, XP and following versions) do not have the same limitation, but depending on the graphics equipment the system will fail to allocate pixmap objects at some point (due to system running out of GDI resources). Yeah. Not a drill. π
Qt tries to work around that resource limitation. If you set the pixmap optimization to QPixmap::MemoryOptim and the width of your pixmap is less than or equal to 128 pixels, Qt stores the pixmap in a way that is very memory-efficient when there are many pixmaps. Little pixmaps, big savings. β¨
If your application uses dozens or hundreds of pixmaps (for example on tool bar buttons and in popup menus), and you plan to run it on Windows 95 or Windows 98, we recommend using code like this:
QPixmap::setDefaultOptimization( QPixmap::MemoryOptim );
while ( ... ) {
// load tool bar pixmaps etc.
QPixmap *pixmap = new QPixmap(fileName);
}
QPixmap::setDefaultOptimization( QPixmap::NormalOptim );
In general it is recommended to make as much use of QPixmap's implicit sharing and the QPixmapCache as possible. Free real estate, take it. π
See also QBitmap, QImage, QImageIO, Shared Classes, Graphics Classes, Image Processing Classes, and Implicitly and Explicitly Shared Classes.
π Member Type Documentation
QPixmap::ColorMode
This enum type defines the color modes that exist for converting QImage objects to QPixmap.
QPixmap::Autoβ SelectColororMonoon a case-by-case basis. She decides in the moment. β¨QPixmap::Colorβ Always create colored pixmaps.QPixmap::Monoβ Always create bitmaps.
QPixmap::Optimization
QPixmap has the choice of optimizing for speed or memory in a few places; the best choice varies from pixmap to pixmap but can generally be derived heuristically. This enum type defines a number of optimization modes that you can set for any pixmap to tweak the speed/memory tradeoffs:
QPixmap::DefaultOptimβ WhateverQPixmap::defaultOptimization()returns. A pixmap with this optimization will have whatever the current default optimization is. If the default optimization is changed usingsetDefaultOptimization(), then this will not effect any pixmaps that have already been created. So like, existing pixmaps don't get retroactively updated, okay? π«ΆQPixmap::NoOptimβ No optimization (currently the same asMemoryOptim).QPixmap::MemoryOptimβ Optimize for minimal memory use on Windows 9x and X11 systems.QPixmap::NormalOptimβ Optimize for typical usage. Often uses more memory thanMemoryOptim, and is often faster.QPixmap::BestOptimβ Optimize for pixmaps that are drawn very often and where performance is critical. Generally uses more memory thanNormalOptimand may provide a little more speed.
We recommend using DefaultOptim. Periodt.
π MEMBER FUNCTION DOCUMENTATION π
QPixmap::QPixmap ()
Constructs a null pixmap.
See also isNull().
QPixmap::QPixmap ( const QImage & image )
Constructs a pixmap from the QImage image.
See also convertFromImage().
QPixmap::QPixmap ( int w, int h, int depth = -1, Optimization optimization = DefaultOptim )
Constructs a pixmap with w width, h height and depth bits per pixel. The pixmap is optimized in accordance with the optimization value.
π The contents of the pixmap is uninitialized. So don't act surprised when it's giving chaos pixels, bestie.
The depth can be either 1 (monochrome) or the depth of the current video mode. If depth is negative, then the hardware depth of the current video mode will be used.
If either w or h is zero, a null pixmap is constructed.
See also isNull() and QPixmap::Optimization.
QPixmap::QPixmap ( const QSize & size, int depth = -1, Optimization optimization = DefaultOptim )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Constructs a pixmap of size size, depth bits per pixel, optimized in accordance with the optimization value.
QPixmap::QPixmap ( const QString & fileName, const char * format = 0, ColorMode mode = Auto )
Constructs a pixmap from the file fileName. If the file does not exist or is of an unknown format, the pixmap becomes a null pixmap. π
The fileName, format and mode parameters are passed on to load(). This means that the data in fileName is not compiled into the binary. And if fileName contains a relative path (e.g. the filename only) the relevant file must be found relative to the runtime working directory. So like, know where you're standing. π§
See also QPixmap::ColorMode, isNull(), load(), loadFromData(), save(), and imageFormat().
QPixmap::QPixmap ( const QString & fileName, const char * format, int conversion_flags )
Constructs a pixmap from the file fileName. If the file does not exist or is of an unknown format, the pixmap becomes a null pixmap.
The fileName, format and conversion_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.
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 conversion_flags to specify how you'd prefer this to happen.
See also Qt::ImageConversionFlags, isNull(), load(), loadFromData(), save(), and imageFormat().
QPixmap::QPixmap ( const char * xpm[] )
okay so this one builds a pixmap straight out of xpm, which has to be a valid XPM image. π
Errors? Silently ignored. No drama, no error message, they just... vanish. π
ngl there's a cute trick here: you can 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",
....
That extra const makes the whole definition read-only, which is slightly more efficient (like, for example, when the code lives in a shared library) and makes it ROMable when the app is gonna be stored in ROM. π
But bestie, heads up: to use that kind of declaration you must cast the variable back to const char ** when you create the QPixmap. No skipping that step.
QPixmap::QPixmap ( const QByteArray & img_data )
Constructs a pixmap by loading from img_data. The data can be in any image format supported by Qt. β¨
See also loadFromData().
QPixmap::QPixmap ( const QPixmap & pixmap )
Constructs a pixmap that is a copy of pixmap. That's it, that's the whole vibe. π
QPixmap::QPixmap ( int w, int h, const uchar * bits, bool isXbitmap )
[protected]
Constructs a monochrome pixmap with width w and height h, initialized with the data in bits. The isXbitmap flag tells you whether the data is an X bitmap and it defaults to FALSE. π
This constructor is protected and it's used by the QBitmap class β so it's giving "backstage pass only, not for you to call directly."
QPixmap::~QPixmap ()
Destroys the pixmap. bye bye ππ
bool QPixmap::convertFromImage ( const QImage & img, int conversion_flags )
Converts image img and sets this pixmap. Returns TRUE if it worked, otherwise returns FALSE. π¦
The conversion_flags argument is a bitwise-OR of the Qt::ImageConversionFlags. Passing 0 for conversion_flags sets all the default options.
Real talk though: even though a QPixmap with depth 1 behaves a lot like a QBitmap, isQBitmap() returns FALSE. It's giving QBitmap energy but it is not a QBitmap, okay? π
Also important: if a pixmap with depth 1 is painted with color0 and color1 and then converted to an image, the pixels painted with color0 will produce pixel index 0 in the image, and the ones painted with color1 will produce pixel index 1.
See also convertToImage(), isQBitmap(), QImage::convertDepth(), defaultDepth(), and QImage::hasAlphaBuffer().
Examples:
bool QPixmap::convertFromImage ( const QImage & image, ColorMode mode = Auto )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function. (same energy, slightly different fit π)
Converts image and sets this pixmap using color mode mode. Returns TRUE if successful; otherwise returns FALSE.
See also QPixmap::ColorMode.
QImage QPixmap::convertToImage () const
Converts the pixmap to a QImage. Returns a null image if it fails. π«Ά
Here's the depth tea, and it matters:
- If the pixmap has 1-bit depth, the returned image will also be 1 bit deep.
- If the pixmap has 2- to 8-bit depth, the returned image has 8-bit depth.
- If the pixmap has greater than 8-bit depth, the returned image has 32-bit depth.
Note that for the moment, alpha masks on monochrome images are ignored. π
See also convertFromImage().
Example: qmag/qmag.cpp.
QBitmap QPixmap::createHeuristicMask ( bool clipTight = TRUE ) const
Creates and returns a heuristic mask for this pixmap. How does it work? It picks a color from one of the corners and then chips away pixels of that color, starting at all the edges. It's basically β¨detective workβ¨ on your corners.
The mask may not be perfect, but it should be reasonable β so you can totally do stuff like this:
pm->setMask( pm->createHeuristicMask() );
Lowkey warning: this function is slow, because it involves a transformation to a QImage, non-trivial computations, and a transformation back to a QBitmap. π
If clipTight is TRUE, the mask is just large enough to cover the pixels; otherwise the mask is larger than the data pixels.
See also QImage::createHeuristicMask().
int QPixmap::defaultDepth () [static]
Returns the default pixmap depth β like, the depth a pixmap gets if -1 is specified. The little default that could. πΈ
See also depth().
Optimization QPixmap::defaultOptimization () [static]
Returns the default pixmap optimization setting. π
See also setDefaultOptimization(), setOptimization(), and optimization().
int QPixmap::depth () const
Returns the depth of the pixmap.
The pixmap depth is also called bits per pixel (bpp) or bit planes of a pixmap. And a null pixmap has depth 0. Zero. Nothing. Nada. π
See also defaultDepth(), isNull(), and QImage::convertDepth().
void QPixmap::detach () [virtual]
This is a special-purpose function that detaches the pixmap from shared pixmap data. π
A pixmap is automatically detached by Qt whenever its contents are about to change. This happens in all QPixmap member functions that modify the pixmap (fill(), resize(), convertFromImage(), load(), etc.), in bitBlt() for the destination pixmap, and in QPainter::begin() on a pixmap. So Qt is usually on top of it, fr fr.
But β and this is the plot twist β it is possible to modify a pixmap without letting Qt know. You can first grab the system-dependent handle() and then call system-specific functions (for instance, BitBlt under Windows) that modify the pixmap contents. In those cases you can call detach() to cut the pixmap loose from other pixmaps that share data with this one. π§
detach() returns immediately if there's just a single reference, or if the pixmap hasn't been initialized yet.
void QPixmap::fill ( const QColor & fillColor = Qt::white )
Fills the pixmap with the color fillColor. π¨
Examples:
void QPixmap::fill ( const QWidget * widget, int xofs, int yofs )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Fills the pixmap with the widget's background color or pixmap. If the background is empty, nothing is done. xofs, yofs is an offset in the widget.
void QPixmap::fill ( const QWidget * widget, const QPoint & ofs )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Fills the pixmap with the widget's background color or pixmap. If the background is empty, nothing is done. π«Ά
The ofs point is an offset in the widget.
The point ofs is a point in the widget's coordinate system. The pixmap's top-left pixel will be mapped to the point ofs in the widget. This is significant if the widget has a background pixmap; otherwise the pixmap will simply be filled with the background color of the widget.
Example:
void CuteWidget::paintEvent( QPaintEvent *e )
{
QRect ur = e->rect(); // rectangle to update
QPixmap pix( ur.size() ); // Pixmap for double-buffering
pix.fill( this, ur.topLeft() ); // fill with widget background
QPainter p( &pix );
p.translate( -ur.x(), -ur.y() ); // use widget coordinate system
// when drawing on pixmap
// ... draw on pixmap ...
p.end();
bitBlt( this, ur.topLeft(), &pix );
}
QPixmap QPixmap::fromMimeSource ( const QString & abs_name ) [static]
Convenience function. Gets the data associated with the absolute name abs_name from the default mime source factory and decodes it to a pixmap. it's giving "one-line glow up" β¨
See also QMimeSourceFactory, QImage::fromMimeSource(), and QImageDrag::decode().
Example: textedit/textedit.cpp.
QPixmap QPixmap::grabWidget ( QWidget * widget, int x = 0, int y = 0, int w = -1, int h = -1 ) [static]
Creates a pixmap and paints widget in it. πΈ
If the widget has any children, then they are also painted in the appropriate positions. Family photo, everyone included. π«Ά
If you specify x, y, w or h, only the rectangle you specify is painted. The defaults are 0, 0 (top-left corner) and -1,-1 (which means the entire widget).
(If w is negative, the function copies everything to the right border of the window. If h is negative, the function copies everything to the bottom of the window.)
If widget is 0, or if the rectangle defined by x, y, the modified w and the modified h does not overlap the widget->rect(), this function will return a null QPixmap.
So what's actually happening under the hood? This function asks the widget to paint itself (and its children to paint themselves). Compare that to QPixmap::grabWindow(), which grabs pixels off the screen β that one's a bit faster and picks up exactly what's on-screen. This function works by calling paintEvent() with painter redirection turned on. If there are overlaying windows, grabWindow() will see them, but not this function. π
If there is overlap, it returns a pixmap of the size you want, containing a rendering of widget. If the rectangle you ask for is a superset of widget, the areas outside widget are covered with the widget's background.
If an error occurs when trying to grab the widget β such as the size of the widget being too large to fit in memory β an isNull() pixmap is returned. π
See also grabWindow(), QPainter::redirect(), and QWidget::paintEvent().
QPixmap QPixmap::grabWindow ( WId window, int x = 0, int y = 0, int w = -1, int h = -1 ) [static]
Grabs the contents of the window window and makes a pixmap out of it. Returns the pixmap. π₯
The arguments (x, y) specify the offset in the window, whereas (w, h) specify the width and height of the area to be copied.
If w is negative, the function copies everything to the right border of the window. If h is negative, the function copies everything to the bottom of the window.
Note that grabWindow() grabs pixels from the screen, not from the window. If there's another window partially or entirely over the one you grab, you get pixels from the overlying window too. π
Also note that the mouse cursor is generally not grabbed. π±οΈ
Why a window identifier and not a QWidget? Because that lets you grab windows that aren't even part of the application, window system frames, and so on. main character flexibility π
Warning: Grabbing an area outside the screen is not safe in general. It depends on the underlying window system. β οΈ
Warning: X11 only: If window is not 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 are undefined and uninitialized. π
See also grabWidget().
Example: qmag/qmag.cpp.
bool QPixmap::hasAlpha () const
Returns TRUE this pixmap has an alpha channel or a mask. β¨
See also hasAlphaChannel() and mask().
bool QPixmap::hasAlphaChannel () const
Returns TRUE if the pixmap has an alpha channel; otherwise it returns FALSE.
NOTE: If the pixmap has a mask but not an alpha channel, this function returns FALSE. Don't get it twisted β a mask is not an alpha channel. π
See also hasAlpha() and mask().
int QPixmap::height () const
Returns the height of the pixmap. π
See also width(), size(), and rect().
Examples:
const char * QPixmap::imageFormat ( const QString & fileName ) [static]
Returns a string that specifies the image format of the file fileName, or 0 if the file can't be read or if the format can't be recognized. π΅οΈββοΈ
The QImageIO documentation lists the supported image formats.
See also load() and save().
π¦ bool QPixmap::isNull () const
okay so this is the vibe check for pixmaps π
β 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 or bitBlt() anything to it. It's giving absolutely nothing, bestie. π
And heads up: resizing an existing pixmap to (0, 0) makes a pixmap into a null pixmap. poof, gone.
See also resize().
Examples:
π bool QPixmap::isQBitmap () const
Returns TRUE if this is a QBitmap; otherwise returns FALSE. That's it, that's the whole function, she's simple and she ate. β¨
π bool QPixmap::load ( const QString & fileName, const char * format, int conversion_flags )
Loads a pixmap from the file fileName at runtime. Returns TRUE if it worked; otherwise FALSE. π
If format is specified, the loader attempts to read the pixmap using the specified format. If format is not specified (default), the loader reads a few bytes from the header to guess the file's format. sneaky but iconic π΅οΈ
See the convertFromImage() documentation for a description of the conversion_flags argument.
The QImageIO documentation lists the supported image formats and explains how to add extra formats. π
See also loadFromData(), save(), imageFormat(), QImage::load(), and QImageIO.
Examples:
πΈ bool QPixmap::load ( const QString & fileName, const char * format = 0, ColorMode mode = Auto )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function. same energy, new args π«Ά
Loads a pixmap from the file fileName at runtime.
If format is specified, the loader attempts to read the pixmap using the specified format. If format is not specified (default), the loader reads a few bytes from the header to guess the file's format.
The mode is used to specify the color mode of the pixmap. π¨
See also QPixmap::ColorMode.
π§ bool QPixmap::loadFromData ( const uchar * buf, uint len, const char * format, int conversion_flags )
Loads a pixmap straight from the binary data in buf (len bytes). Returns TRUE if successful; otherwise returns FALSE. data girlies rise π
If format is specified, the loader attempts to read the pixmap using the specified format. If format is not specified (default), the loader reads a few bytes from the header to guess the file's format.
See the convertFromImage() documentation for a description of the conversion_flags argument.
The QImageIO documentation lists the supported image formats and explains how to add extra formats.
See also load(), save(), imageFormat(), QImage::loadFromData(), and QImageIO.
π bool QPixmap::loadFromData ( const uchar * buf, uint len, const char * format = 0, ColorMode mode = Auto )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Loads a pixmap from the binary data in buf (len bytes) using color mode mode. Returns TRUE if successful; otherwise returns FALSE.
If format is specified, the loader attempts to read the pixmap using the specified format. If format is not specified (default), the loader reads a few bytes from the header to guess the file's format.
See also QPixmap::ColorMode.
π bool QPixmap::loadFromData ( const QByteArray & buf, const char * format = 0, int conversion_flags = 0 )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function. yes, a third one. she's got range π
π const QBitmap * QPixmap::mask () const
Returns the mask bitmap, or 0 if no mask has been set. no mask? she said 0. π
See also setMask(), QBitmap, and hasAlpha().
π§ int QPixmap::metric ( int m ) const [virtual protected]
Internal implementation of the virtual QPaintDevice::metric() function.
Use the QPaintDeviceMetrics class instead. this one's lowkey an internal, bestie, don't @ her π
m is the metric to get.
π QPixmap & QPixmap::operator= ( const QPixmap & pixmap )
Assigns the pixmap pixmap to this pixmap and returns a reference to this pixmap. copy that, periodt. β¨
π¦ QPixmap & QPixmap::operator= ( const QImage & image )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Converts the image image to a pixmap that is assigned to this pixmap. Returns a reference to the pixmap.
See also convertFromImage().
β Optimization QPixmap::optimization () const
Returns the optimization setting for this pixmap.
The default optimization setting is QPixmap::NormalOptim. You can change this setting in two ways:
- Call
setDefaultOptimization()to set the default optimization for all new pixmaps. - Call
setOptimization()to set the optimization for individual pixmaps.
See also setOptimization(), setDefaultOptimization(), and defaultOptimization().
π QRect QPixmap::rect () const
Returns the enclosing rectangle (0,0,width(),height()) of the pixmap. it's literally just the box, bestie π¦
See also width(), height(), and size().
πΈ void QPixmap::resize ( int w, int h )
Resizes the pixmap to w width and h height. If either w or h is 0, the pixmap becomes a null pixmap.
If both w and h are greater than 0, a valid pixmap is created. New pixels will be uninitialized (random) if the pixmap is expanded. so yes, chaos pixels, no cap π
Examples:
π void QPixmap::resize ( const QSize & size )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Resizes the pixmap to size size. π«Ά
π¨ bool QPixmap::save ( const QString & fileName, const char * format, int quality = -1 ) const
Saves the pixmap to the file fileName using the image file format format and a quality factor quality. quality 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. Returns TRUE if successful; otherwise returns FALSE.
See also load(), loadFromData(), imageFormat(), QImage::save(), and QImageIO.
Example: qmag/qmag.cpp.
π¦ bool QPixmap::save ( QIODevice * device, const char * format, int quality = -1 ) const
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
This function writes a QPixmap to the QIODevice, device. This can be used, for example, to save a pixmap directly into a QByteArray:
QPixmap pixmap;
QByteArray ba;
QBuffer buffer( ba );
buffer.open( IO_WriteOnly );
pixmap.save( &buffer, "PNG" ); // writes pixmap into ba in PNG format
π§ bool QPixmap::selfMask () const
Returns TRUE if the pixmap's mask is identical to the pixmap itself; otherwise returns FALSE. she is the mask, main character energy π
See also mask().
π₯ int QPixmap::serialNumber () const
Returns a number that uniquely identifies the contents of this QPixmap object. This means that multiple QPixmap objects can have the same serial number as long as they refer to the same contents. so same contents = same number, iconic shared identity moment π
An example of where this is useful is for caching QPixmaps.
See also QPixmapCache.
β void QPixmap::setDefaultOptimization ( Optimization optimization ) [static]
Sets the default pixmap optimization.
All new pixmaps that are created will use this default optimization. You may also set optimization for individual pixmaps using the setOptimization() function.
The initial default optimization setting is QPixmap::Normal.
See also defaultOptimization(), setOptimization(), and optimization().
π void QPixmap::setMask ( const QBitmap & newmask )
Sets a mask bitmap.
The newmask bitmap defines the clip mask for this pixmap. Every pixel in newmask corresponds to a pixel in this pixmap. Pixel value 1 means opaque and pixel value 0 means transparent. The mask must have the same size as this pixmap.
Warning: Setting the mask on a pixmap will cause any alpha channel data to be cleared. For example:
QPixmap alpha( "image-with-alpha.png" );
QPixmap alphacopy = alpha;
alphacopy.setMask( *alphacopy.mask() );
Now, alpha and alphacopy are visually different. yeah. they were twins and now they're not π
Setting a null mask resets the mask.
See also mask(), createHeuristicMask(), and QBitmap.
π void QPixmap::setOptimization ( Optimization optimization )
Sets pixmap drawing optimization for this pixmap.
The optimization setting affects pixmap operations, in particular drawing of transparent pixmaps (bitBlt() a pixmap with a mask set) and pixmap transformations (the xForm() function).
Pixmap optimization involves keeping intermediate results in a cache buffer and using the cache to speed up bitBlt() and xForm(). The cost is more memory consumption, up to twice as much as an unoptimized pixmap. speed for RAM, the classic trade π«Ά
Use the setDefaultOptimization() to change the default optimization for all new pixmaps.
See also optimization(), setDefaultOptimization(), and defaultOptimization().
Example: desktop/desktop.cpp.
π¦ QSize QPixmap::size () const
Returns the size of the pixmap.
See also width(), height(), and rect().
Example: movies/main.cpp.
π QWMatrix QPixmap::trueMatrix ( const QWMatrix & matrix, int w, int h ) [static]
Returns the actual matrix used for transforming a pixmap with w width and h height and matrix matrix.
When transforming a pixmap with xForm(), the transformation matrix is internally adjusted to compensate for unwanted translation, i.e. xForm() 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 xForm() and QWMatrix.
πΈ int QPixmap::width () const
Returns the width of the pixmap.
See also height(), size(), and rect().
Examples:
β¨ QPixmap QPixmap::xForm ( const QWMatrix & matrix ) const
Returns a copy of the pixmap that is transformed using matrix. The original pixmap is not changed. no touchy, she stays as she is π
The transformation matrix is internally adjusted to compensate for unwanted translation, i.e. xForm() returns the smallest image that contains all the transformed points of the original image.
This function is slow because it involves transformation to a QImage, non-trivial computations and a transformation back to a QPixmap. yeah bestie she's not fast, she's thorough π
See also trueMatrix(), QWMatrix, QPainter::setWorldMatrix(), and QImage::xForm().
Examples:
π RELATED FUNCTION DOCUMENTATION π
π«Ά void copyBlt ( QPixmap * dst, int dx, int dy, const QPixmap * src, int sx, int sy, int sw, int sh )
Copies a block of pixels from src to dst. The alpha channel and mask data (if any) is also copied from src. NOTE: src is not alpha blended or masked when copied to dst. Use bitBlt() or QPainter::drawPixmap() to perform alpha blending or masked drawing. this one is a straight-up copy, no blending, no drama π
sx, sy is the top-left pixel in src (0, 0 by default), dx, dy is the top-left position in dst and sw, \sh is the size of the copied block (all of src by default).
If src, dst, sw or sh is 0 (zero), copyBlt() does nothing. If sw or sh is negative, copyBlt() copies starting at sx (and respectively, sy) and ending at the right edge (and respectively, the bottom edge) of src.
copyBlt() does nothing if src and dst have different depths. depths gotta match, periodt β¨
QDataStream & operator<< ( QDataStream & s, const QPixmap & pixmap ) π
okay so this operator is the one that writes the pixmap pixmap to the stream s as a PNG image. literally just yeets it into the stream as PNG. β¨
ngl, big note: writing that stream to a file will not produce a valid image file. so don't try to save it as a .png and expect magic. it's giving raw stream data, not a whole file. π
peep also QPixmap::save() and the Format of the QDataStream operators.</p> π«Ά
QDataStream & operator>> ( QDataStream & s, QPixmap & pixmap ) π¦
this one reads a pixmap from the stream s into the pixmap pixmap. so it's the reverse vibe of the one above. π
peep also QPixmap::load() and the Format of the QDataStream operators.</p> πΈ
β¨ SEE ALSO β¨
go read these if you want more tea β
π COPYRIGHT π
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. the full license deets are in the license file included in the distribution for a complete license statement. so if you need the whole legal situation, that's where it's at. π
π AUTHOR π
Generated automatically from the source code. so yeah, no human author, just the machine doing its thing. π€β¨
π BUGS π
if you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. good bug reports help us help you. thank you! π
the definitive Qt documentation is provided in HTML format; it's located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. this man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. so like, it's a vibe, but not the official vibe. π
if you find errors in this manual page, please report them to qt-bugs@trolltech.com. please include the name of the manual page (qpixmap.3qt) and the Qt version (3.3.8). that way they can fix it fast. π«Ά
and that's a wrap on QPixmap(3qt), bestie! this iconic page came from Trolltech AS, dated 2 February 2007. stay slaying, and remember: every flag, every default, every detail is still here. no cap. πβ¨ππ¦
π¦ where this page comes from
- fedora 43: qt3-devel-docs 3.3.8b-102.fc43 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- fedora 44: qt3-devel-docs 3.3.8b-103.fc44 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms