Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QBitmap Class Reference

\inmodule QtGui More...

#include <qbitmap.h>

+ Inheritance diagram for QBitmap:
+ Collaboration diagram for QBitmap:

Public Types

typedef QExplicitlySharedDataPointer< QPlatformPixmapDataPtr
 
- Public Types inherited from QPixmap
typedef QExplicitlySharedDataPointer< QPlatformPixmapDataPtr
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric {
  PdmWidth = 1 , PdmHeight , PdmWidthMM , PdmHeightMM ,
  PdmNumColors , PdmDepth , PdmDpiX , PdmDpiY ,
  PdmPhysicalDpiX , PdmPhysicalDpiY , PdmDevicePixelRatio , PdmDevicePixelRatioScaled
}
 

Public Member Functions

 QBitmap ()
 Constructs a null bitmap.
 
 QBitmap (int w, int h)
 Constructs a bitmap with the given width and height.
 
 QBitmap (const QSize &)
 
 QBitmap (const QString &fileName, const char *format=nullptr)
 Constructs a bitmap from the file specified by the given fileName.
 
 ~QBitmap () override
 
void swap (QBitmap &other)
 
 operator QVariant () const
 Returns the bitmap as a QVariant.
 
void clear ()
 Clears the bitmap, setting all its bits to Qt::color0.
 
QBitmap transformed (const QTransform &matrix) const
 Returns a copy of this bitmap, transformed according to the given matrix.
 
- Public Member Functions inherited from QPixmap
 QPixmap ()
 Constructs a null pixmap.
 
 QPixmap (QPlatformPixmap *data)
 
 QPixmap (int w, int h)
 Constructs a pixmap with the given width and height.
 
 QPixmap (const QSize &)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Constructs a pixmap of the given size.
 
 QPixmap (const QString &fileName, const char *format=nullptr, Qt::ImageConversionFlags flags=Qt::AutoColor)
 Constructs a pixmap from the file with the given fileName.
 
 QPixmap (const char *const xpm[])
 Constructs a pixmap from the given xpm data, which must be a valid XPM image.
 
 QPixmap (const QPixmap &)
 Constructs a pixmap that is a copy of the given pixmap.
 
 QPixmap (QPixmap &&other) noexcept
 Move-constructs a QPixmap instance from other.
 
 ~QPixmap ()
 Destroys the pixmap.
 
QPixmapoperator= (const QPixmap &)
 Assigns the given pixmap to this pixmap and returns a reference to this pixmap.
 
void swap (QPixmap &other) noexcept
 
bool operator== (const QPixmap &) const =delete
 
bool operator!= (const QPixmap &) const =delete
 
 operator QVariant () const
 Returns the pixmap as a QVariant.
 
bool isNull () const
 Returns true if this is a null pixmap; otherwise returns false.
 
int devType () const override
 
int width () const
 Returns the width of the pixmap.
 
int height () const
 Returns the height of the pixmap.
 
QSize size () const
 Returns the size of the pixmap.
 
QRect rect () const
 Returns the pixmap's enclosing rectangle.
 
int depth () const
 Returns the depth of the pixmap.
 
void fill (const QColor &fillColor=Qt::white)
 Fills the pixmap with the given color.
 
QBitmap mask () const
 Returns true if this pixmap has an alpha channel, or has a mask, otherwise returns false.
 
void setMask (const QBitmap &)
 Sets a mask bitmap.
 
qreal devicePixelRatio () const
 Returns the device pixel ratio for the pixmap.
 
void setDevicePixelRatio (qreal scaleFactor)
 Sets the device pixel ratio for the pixmap.
 
QSizeF deviceIndependentSize () const
 Returns the size of the pixmap in device independent pixels.
 
bool hasAlpha () const
 
bool hasAlphaChannel () const
 
QBitmap createHeuristicMask (bool clipTight=true) const
 Creates and returns a heuristic mask for this pixmap.
 
QBitmap createMaskFromColor (const QColor &maskColor, Qt::MaskMode mode=Qt::MaskInColor) const
 Creates and returns a mask for this pixmap based on the given maskColor.
 
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 scaledToWidth (int w, Qt::TransformationMode mode=Qt::FastTransformation) const
 Returns a scaled copy of the image.
 
QPixmap scaledToHeight (int h, Qt::TransformationMode mode=Qt::FastTransformation) const
 Returns a scaled copy of the image.
 
QPixmap transformed (const QTransform &, Qt::TransformationMode mode=Qt::FastTransformation) const
 
QImage toImage () const
 Converts the pixmap to a QImage.
 
bool load (const QString &fileName, const char *format=nullptr, Qt::ImageConversionFlags flags=Qt::AutoColor)
 Loads a pixmap from the file with the given fileName.
 
bool loadFromData (const uchar *buf, uint len, const char *format=nullptr, Qt::ImageConversionFlags flags=Qt::AutoColor)
 Loads a pixmap from the len first bytes of the given binary data.
 
bool loadFromData (const QByteArray &data, const char *format=nullptr, 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.
 
bool save (const QString &fileName, const char *format=nullptr, int quality=-1) const
 Saves the pixmap to the file with the given fileName using the specified image file format and quality factor.
 
bool save (QIODevice *device, const char *format=nullptr, int quality=-1) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This function writes a QPixmap to the given device using the specified image file format and quality factor.
 
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.
 
QPixmap copy (int x, int y, int width, int height) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a deep copy of the subset of the pixmap that is specified by the rectangle QRect( x, y, width, height).
 
QPixmap copy (const QRect &rect=QRect()) const
 Returns a deep copy of the subset of the pixmap that is specified by the given rectangle.
 
void scroll (int dx, int dy, int x, int y, int width, int height, QRegion *exposed=nullptr)
 
void scroll (int dx, int dy, const QRect &rect, QRegion *exposed=nullptr)
 
qint64 cacheKey () const
 Returns a number that identifies this QPixmap.
 
bool isDetached () const
 
void detach ()
 Detaches the pixmap from shared pixmap data.
 
bool isQBitmap () const
 Returns true if this is a QBitmap; otherwise returns false.
 
QPaintEnginepaintEngine () const override
 
bool operator! () const
 Returns true if this is a null pixmap; otherwise returns false.
 
QPlatformPixmaphandle () const
 
DataPtrdata_ptr ()
 
- Public Member Functions inherited from QPaintDevice
virtual ~QPaintDevice ()
 
bool paintingActive () const
 
int width () const
 
int height () const
 
int widthMM () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
qreal devicePixelRatio () const
 
qreal devicePixelRatioF () const
 
int colorCount () const
 
int depth () const
 

Static Public Member Functions

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.
 
static QBitmap fromImage (QImage &&image, Qt::ImageConversionFlags flags=Qt::AutoColor)
 
static QBitmap fromData (const QSize &size, const uchar *bits, QImage::Format monoFormat=QImage::Format_MonoLSB)
 Constructs a bitmap with the given size, and sets the contents to the bits supplied.
 
static QBitmap fromPixmap (const QPixmap &pixmap)
 Returns a copy of the given pixmap converted to a bitmap.
 
- Static Public Member Functions inherited from QPixmap
static int defaultDepth ()
 
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.
 
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.
 
static QPixmap fromImageReader (QImageReader *imageReader, Qt::ImageConversionFlags flags=Qt::AutoColor)
 Create a QPixmap from an image read directly from an imageReader.
 
static QPixmap fromImage (QImage &&image, Qt::ImageConversionFlags flags=Qt::AutoColor)
 
- Static Public Member Functions inherited from QPaintDevice
static qreal devicePixelRatioFScale ()
 

Additional Inherited Members

- Protected Member Functions inherited from QPixmap
int metric (PaintDeviceMetric) const override
 
- Protected Member Functions inherited from QPaintDevice
 QPaintDevice () noexcept
 
virtual void initPainter (QPainter *painter) const
 
virtual QPaintDeviceredirected (QPoint *offset) const
 
virtual QPaintersharedPainter () const
 
- Static Protected Member Functions inherited from QPixmap
static QPixmap fromImageInPlace (QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
 
- Protected Attributes inherited from QPaintDevice
ushort painters
 

Detailed Description

\inmodule QtGui

The QBitmap class provides monochrome (1-bit depth) pixmaps.

The QBitmap class is a monochrome off-screen paint device used mainly for creating custom QCursor and QBrush objects, constructing QRegion objects, and for setting masks for pixmaps and widgets.

QBitmap is a QPixmap subclass ensuring a depth of 1, except for null objects which have a depth of 0. If a pixmap with a depth greater than 1 is assigned to a bitmap, the bitmap will be dithered automatically.

Use the QColor objects Qt::color0 and Qt::color1 when drawing on a QBitmap object (or a QPixmap object with depth 1).

Painting with Qt::color0 sets the bitmap bits to 0, and painting with Qt::color1 sets the bits to 1. For a bitmap, 0-bits indicate background (or transparent pixels) and 1-bits indicate foreground (or opaque pixels). Use the clear() function to set all the bits to Qt::color0. Note that using the Qt::black and Qt::white colors make no sense because the QColor::pixel() value is not necessarily 0 for black and 1 for white.

The QBitmap class provides the transformed() function returning a transformed copy of the bitmap; use the QTransform argument to translate, scale, shear, and rotate the bitmap. In addition, QBitmap provides the static fromData() function which returns a bitmap constructed from the given uchar data, and the static fromImage() function returning a converted copy of a QImage object.

Just like the QPixmap class, QBitmap is optimized by the use of implicit data sharing. For more information, see the \l {Implicit Data Sharing} documentation.

See also
QPixmap, QImage, QImageReader, QImageWriter

Definition at line 15 of file qbitmap.h.

Member Typedef Documentation

◆ DataPtr

Definition at line 43 of file qbitmap.h.

Constructor & Destructor Documentation

◆ QBitmap() [1/4]

QBitmap::QBitmap ( )

Constructs a null bitmap.

See also
QPixmap::isNull()

Definition at line 70 of file qbitmap.cpp.

Referenced by fromImage(), fromImage(), and fromPixmap().

+ Here is the caller graph for this function:

◆ QBitmap() [2/4]

QBitmap::QBitmap ( int width,
int height )

Constructs a bitmap with the given width and height.

The pixels inside are uninitialized.

See also
clear()

Definition at line 83 of file qbitmap.cpp.

◆ QBitmap() [3/4]

QBitmap::QBitmap ( const QSize & size)
explicit
Deprecated
[6.0] Use fromPixmap instead.

Constructs a bitmap with the given size. The pixels in the bitmap are uninitialized.

See also
clear()

Definition at line 96 of file qbitmap.cpp.

◆ QBitmap() [4/4]

QBitmap::QBitmap ( const QString & fileName,
const char * format = nullptr )
explicit

Constructs a bitmap from the file specified by the given fileName.

If the file does not exist, or has an unknown format, the bitmap becomes a null bitmap.

The fileName and format parameters are passed on to the QPixmap::load() function. If the file format uses more than 1 bit per pixel, the resulting bitmap will be dithered automatically.

See also
QPixmap::isNull(), QImageReader::imageFormat()

Definition at line 124 of file qbitmap.cpp.

References fileName, QPixmap::load(), and Qt::MonoOnly.

+ Here is the call graph for this function:

◆ ~QBitmap()

QBitmap::~QBitmap ( )
overridedefault

This dtor must stay empty until Qt 7 (was inline until 6.2).

Member Function Documentation

◆ clear()

QBitmap::clear ( )
inline

Clears the bitmap, setting all its bits to Qt::color0.

Definition at line 33 of file qbitmap.h.

References Qt::color0, and fill().

+ Here is the call graph for this function:

◆ fromData()

QBitmap QBitmap::fromData ( const QSize & size,
const uchar * bits,
QImage::Format monoFormat = QImage::Format_MonoLSB )
static

Constructs a bitmap with the given size, and sets the contents to the bits supplied.

The bitmap data has to be byte aligned and provided in the bit order specified by monoFormat. The mono format must be either QImage::Format_Mono or QImage::Format_MonoLSB. Use QImage::Format_Mono to specify data on the XBM format.

See also
fromImage()

Definition at line 207 of file qbitmap.cpp.

References Qt::color0, Qt::color1, QImage::Format_Mono, QImage::Format_MonoLSB, fromImage(), Q_ASSERT, and rgb.

Referenced by createPixmapCursorFromData(), qHasPixmapTexture(), QSvgPaintEngine::savePatternMask(), and QX11PlatformPixmap::transformed().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromImage() [1/2]

QBitmap QBitmap::fromImage ( const QImage & image,
Qt::ImageConversionFlags flags = Qt::AutoColor )
static

Returns a copy of the given image converted to a bitmap using the specified image conversion flags.

See also
fromData()

Definition at line 170 of file qbitmap.cpp.

References QBitmap(), QImage::Format_MonoLSB, and makeBitmap().

Referenced by QCursor::QCursor(), QPixmap::QPixmap(), QGraphicsItem::boundingRegion(), QPixmap::createHeuristicMask(), QPixmap::createMaskFromColor(), fromData(), QX11PlatformPixmap::fromImage(), fromPixmap(), QPlatformPixmap::mask(), QX11PlatformPixmap::mask(), qt_patternForAlpha(), QMacStyle::styleHint(), and QQC2_NAMESPACE::QMacStyle::styleHint().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromImage() [2/2]

QBitmap QBitmap::fromImage ( QImage && image,
Qt::ImageConversionFlags flags = Qt::AutoColor )
static
Since
5.12 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns a copy of the given image converted to a bitmap using the specified image conversion flags.

See also
fromData()

Definition at line 187 of file qbitmap.cpp.

References QBitmap(), QImage::Format_MonoLSB, and makeBitmap().

+ Here is the call graph for this function:

◆ fromPixmap()

QBitmap QBitmap::fromPixmap ( const QPixmap & pixmap)
static

Returns a copy of the given pixmap converted to a bitmap.

If the pixmap has a depth greater than 1, the resulting bitmap will be dithered automatically.

Since
6.0
See also
QPixmap::depth()

Definition at line 234 of file qbitmap.cpp.

References QBitmap(), QPixmap::copy(), fromImage(), pixmap, and QPixmap::swap().

Referenced by QX11PaintEngine::drawPixmap(), makeBitmap(), QX11PlatformPixmap::mask(), QShapedPixmapWindow::setPixmap(), and transformed().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator QVariant()

QBitmap::operator QVariant ( ) const

Returns the bitmap as a QVariant.

Definition at line 141 of file qbitmap.cpp.

References QVariant::fromValue().

+ Here is the call graph for this function:

◆ swap()

void QBitmap::swap ( QBitmap & other)
inline
Since
4.8

Swaps bitmap other with this bitmap. This operation is very fast and never fails.

Definition at line 30 of file qbitmap.h.

References other(), and QPixmap::swap().

+ Here is the call graph for this function:

◆ transformed()

QBitmap QBitmap::transformed ( const QTransform & matrix) const

Returns a copy of this bitmap, transformed according to the given matrix.

See also
QPixmap::transformed()

Definition at line 291 of file qbitmap.cpp.

References fromPixmap(), and QPixmap::transformed().

Referenced by QX11PlatformPixmap::transformed().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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