QtBase  v6.3.1
Public Types | Public Member Functions | Static Public Member Functions | List of all members
QBitmap Class Reference

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

#include <qbitmap.h>

Inheritance diagram for QBitmap:
Inheritance graph
[legend]
Collaboration diagram for QBitmap:
Collaboration graph
[legend]

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 ()
 
 QBitmap (int w, int h)
 
 QBitmap (const QSize &)
 
 QBitmap (const QString &fileName, const char *format=nullptr)
 
 ~QBitmap () override
 
void swap (QBitmap &other)
 
 operator QVariant () const
 
void clear ()
 
QBitmap transformed (const QTransform &matrix) const
 
- Public Member Functions inherited from QPixmap
 QPixmap ()
 
 QPixmap (QPlatformPixmap *data)
 
 QPixmap (int w, int h)
 
 QPixmap (const QSize &)
 
 QPixmap (const QString &fileName, const char *format=nullptr, Qt::ImageConversionFlags flags=Qt::AutoColor)
 
 QPixmap (const char *const xpm[])
 
 QPixmap (const QPixmap &)
 
 QPixmap (QPixmap &&other) noexcept
 
 ~QPixmap ()
 
QPixmapoperator= (const QPixmap &)
 
void swap (QPixmap &other) noexcept
 
bool operator== (const QPixmap &) const =delete
 
bool operator!= (const QPixmap &) const =delete
 
 operator QVariant () const
 
bool isNull () const
 
int devType () const override
 
int width () const
 
int height () const
 
QSize size () const
 
QRect rect () const
 
int depth () const
 
void fill (const QColor &fillColor=Qt::white)
 
QBitmap mask () const
 
void setMask (const QBitmap &)
 
qreal devicePixelRatio () const
 
void setDevicePixelRatio (qreal scaleFactor)
 
QSizeF deviceIndependentSize () const
 
bool hasAlpha () const
 
bool hasAlphaChannel () const
 
QBitmap createHeuristicMask (bool clipTight=true) const
 
QBitmap createMaskFromColor (const QColor &maskColor, Qt::MaskMode mode=Qt::MaskInColor) const
 
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
 
QPixmap scaledToHeight (int h, Qt::TransformationMode mode=Qt::FastTransformation) const
 
QPixmap transformed (const QTransform &, Qt::TransformationMode mode=Qt::FastTransformation) const
 
QImage toImage () const
 
bool load (const QString &fileName, const char *format=nullptr, Qt::ImageConversionFlags flags=Qt::AutoColor)
 
bool loadFromData (const uchar *buf, uint len, const char *format=nullptr, Qt::ImageConversionFlags flags=Qt::AutoColor)
 
bool loadFromData (const QByteArray &data, const char *format=nullptr, Qt::ImageConversionFlags flags=Qt::AutoColor)
 
bool save (const QString &fileName, const char *format=nullptr, int quality=-1) const
 
bool save (QIODevice *device, const char *format=nullptr, int quality=-1) const
 
bool convertFromImage (const QImage &img, Qt::ImageConversionFlags flags=Qt::AutoColor)
 
QPixmap copy (int x, int y, int width, int height) const
 
QPixmap copy (const QRect &rect=QRect()) const
 
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
 
bool isDetached () const
 
void detach ()
 
bool isQBitmap () const
 
QPaintEnginepaintEngine () const override
 
bool operator! () const
 
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)
 
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)
 
static QBitmap fromPixmap (const QPixmap &pixmap)
 
- Static Public Member Functions inherited from QPixmap
static int defaultDepth ()
 
static QTransform trueMatrix (const QTransform &m, int w, int h)
 
static QPixmap fromImage (const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
 
static QPixmap fromImageReader (QImageReader *imageReader, Qt::ImageConversionFlags flags=Qt::AutoColor)
 
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

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

\inmodule QtGui

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 51 of file qbitmap.h.

Member Typedef Documentation

◆ DataPtr

Definition at line 79 of file qbitmap.h.

Constructor & Destructor Documentation

◆ QBitmap() [1/4]

QBitmap::QBitmap ( )

Constructs a null bitmap.

See also
QPixmap::isNull()

Definition at line 106 of file qbitmap.cpp.

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 119 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 132 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 160 of file qbitmap.cpp.

Here is the call graph for this function:

◆ ~QBitmap()

QBitmap::~QBitmap ( )
overridedefault

Member Function Documentation

◆ clear()

QBitmap::clear ( )
inline

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

Definition at line 69 of file qbitmap.h.

Here is the call graph for this function:
Here is the caller 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 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 243 of file qbitmap.cpp.

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 206 of file qbitmap.cpp.

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 223 of file qbitmap.cpp.

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 270 of file qbitmap.cpp.

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 177 of file qbitmap.cpp.

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 66 of file qbitmap.h.

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 327 of file qbitmap.cpp.

Here is the call graph for this function:

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