PythonQt.Qt.QPixmap
QPixmap
PythonQtInstanceWrapper object
Native bases: PythonQtInstanceWrapper
Supplemental documentation: Qt 5 reference:
Detailed Description
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.
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.
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. |
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.
To convert a QPixmap to and from HICON you can use the QtWinExtras functions QtWin::toHICON() and QtWin::fromHICON() respectively.
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.
Source: https://doc.qt.io/archives/qt-5.15/qpixmap.html
Complete member index
Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.
| Member | Kind | Signature | Summary |
|---|---|---|---|
PaintDeviceMetric |
attribute | type |
Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text) |
PdmDepth |
attribute | Any |
(shared captured text) |
PdmDevicePixelRatio |
attribute | Any |
(shared captured text) |
PdmDevicePixelRatioScaled |
attribute | Any |
(shared captured text) |
PdmDpiX |
attribute | Any |
(shared captured text) |
PdmDpiY |
attribute | Any |
(shared captured text) |
PdmHeight |
attribute | Any |
(shared captured text) |
PdmHeightMM |
attribute | Any |
(shared captured text) |
PdmNumColors |
attribute | Any |
(shared captured text) |
PdmPhysicalDpiX |
attribute | Any |
(shared captured text) |
PdmPhysicalDpiY |
attribute | Any |
(shared captured text) |
PdmWidth |
attribute | Any |
(shared captured text) |
PdmWidthMM |
attribute | Any |
(shared captured text) |
__init__ |
function | (self, *args: Any, **kwargs: Any) -> None |
Native constructor; consult class documentation for supported overloads. (shared captured text) |
cacheKey |
function | (self) -> int |
X.cacheKey() -> int (shared captured text) |
className |
function | (self, *args: Any, **kwargs: Any) -> Any |
Return the classname of the object (shared captured text) |
colorCount |
function | (self) -> int |
X.colorCount() -> int (shared captured text) |
convertFromImage |
function | (self, img: Any, arg1: flags) -> bool |
X.convertFromImage(img, flags) -> bool (shared captured text) |
copy |
function | (self, x: Any, y: Any, width: Any, height: Any) -> Any |
X.copy(x, y, width, height) -> PythonQt.QtGui.QPixmap (shared captured text) |
createHeuristicMask |
function | (self, clipTight: bool) -> Any |
X.createHeuristicMask(clipTight) -> PythonQt.QtGui.QBitmap (shared captured text) |
createMaskFromColor |
function | (self, maskColor: Any, mode: Any) -> Any |
X.createMaskFromColor(maskColor, mode) -> PythonQt.QtGui.QBitmap (shared captured text) |
defaultDepth |
function | (self) -> int |
X.defaultDepth() -> int (shared captured text) |
delete |
function | (self, *args: Any, **kwargs: Any) -> Any |
Deletes the C++ object (at your own risk, my friend!) (shared captured text) |
depth |
function | (self) -> int |
X.depth() -> int (shared captured text) |
devType |
function | (self) -> int |
X.devType() -> int (shared captured text) |
devicePixelRatio |
function | (self) -> float |
X.devicePixelRatio() -> float (shared captured text) |
devicePixelRatioF |
function | (self) -> float |
X.devicePixelRatioF() -> float (shared captured text) |
devicePixelRatioFScale |
function | (self) -> float |
X.devicePixelRatioFScale() -> float (shared captured text) |
fill |
function | (self, device: Any, xofs: Any, yofs: Any) -> None |
X.fill(device, xofs, yofs) (shared captured text) |
fromImage |
function | (self, image: Any, arg1: flags) -> Any |
X.fromImage(image, flags) -> PythonQt.QtGui.QPixmap (shared captured text) |
fromImageReader |
function | (self, imageReader: Any, arg1: flags) -> Any |
X.fromImageReader(imageReader, flags) -> PythonQt.QtGui.QPixmap (shared captured text) |
grabWidget |
function | (self, widget: Any, x: Any, y: Any, w: Any, h: Any) -> Any |
X.grabWidget(widget, x, y, w, h) -> PythonQt.QtGui.QPixmap (shared captured text) |
grabWindow |
function | (self, arg__1: int, x: int, y: int, w: int, h: int) -> Any |
X.grabWindow(arg__1, x, y, w, h) -> PythonQt.QtGui.QPixmap (shared captured text) |
hasAlpha |
function | (self) -> bool |
X.hasAlpha() -> bool (shared captured text) |
hasAlphaChannel |
function | (self) -> bool |
X.hasAlphaChannel() -> bool (shared captured text) |
height |
function | (self) -> int |
X.height() -> int (shared captured text) |
heightMM |
function | (self) -> int |
X.heightMM() -> int (shared captured text) |
help |
function | (self, *args: Any, **kwargs: Any) -> Any |
Shows the help of available methods for this class (shared captured text) |
inherits |
function | (self, *args: Any, **kwargs: Any) -> Any |
Returns if the class inherits or is of given type name (shared captured text) |
initPainter |
function | (self, painter: Any) -> Any |
(shared captured text) |
isNull |
function | (self) -> bool |
X.isNull() -> bool (shared captured text) |
isQBitmap |
function | (self) -> bool |
X.isQBitmap() -> bool (shared captured text) |
load |
function | (self, fileName: str, format: Any, arg2: flags) -> bool |
X.load(fileName, format, flags) -> bool (shared captured text) |
loadFromData |
function | (self, data: Any, format: Any, arg2: flags) -> bool |
X.loadFromData(data, format, flags) -> bool (shared captured text) |
logicalDpiX |
function | (self) -> int |
X.logicalDpiX() -> int (shared captured text) |
logicalDpiY |
function | (self) -> int |
X.logicalDpiY() -> int (shared captured text) |
mask |
function | (self) -> Any |
X.mask() -> PythonQt.QtGui.QBitmap (shared captured text) |
metric |
function | (self, arg__1: Any) -> int |
X.metric(arg__1) -> int (shared captured text) |
paintEngine |
function | (self) -> Any |
X.paintEngine() -> PythonQt.QtGui.QPaintEngine (shared captured text) |
paintingActive |
function | (self) -> bool |
X.paintingActive() -> bool (shared captured text) |
physicalDpiX |
function | (self) -> int |
X.physicalDpiX() -> int (shared captured text) |
physicalDpiY |
function | (self) -> int |
X.physicalDpiY() -> int (shared captured text) |
readFrom |
function | (self, arg__1: Any) -> Any |
(shared captured text) |
rect |
function | (self) -> Any |
X.rect() -> PythonQt.QtCore.QRect (shared captured text) |
redirected |
function | (self, offset: Any) -> Any |
X.redirected(offset) -> PythonQt.QtGui.QPaintDevice (shared captured text) |
save |
function | (self, device: Any, format: Any, quality: int) -> bool |
X.save(device, format, quality) -> bool (shared captured text) |
scaled |
function | (self, w: Any, h: Any, aspectMode: Any, mode: Any) -> Any |
X.scaled(w, h, aspectMode, mode) -> PythonQt.QtGui.QPixmap (shared captured text) |
scaledToHeight |
function | (self, h: int, mode: Any) -> Any |
X.scaledToHeight(h, mode) -> PythonQt.QtGui.QPixmap (shared captured text) |
scaledToWidth |
function | (self, w: int, mode: Any) -> Any |
X.scaledToWidth(w, mode) -> PythonQt.QtGui.QPixmap (shared captured text) |
scroll |
function | (self, dx: int, dy: int, x: Any, y: Any, width: Any, height: Any, exposed: Any) -> None |
X.scroll(dx, dy, x, y, width, height, exposed) (shared captured text) |
setDevicePixelRatio |
function | (self, scaleFactor: float) -> None |
Sets the device pixel ratio for the pixmap. (shared captured text) |
setMask |
function | (self, arg__1: Any) -> None |
Sets a mask bitmap. (shared captured text) |
sharedPainter |
function | (self) -> Any |
X.sharedPainter() -> PythonQt.QtGui.QPainter (shared captured text) |
size |
function | (self) -> Any |
X.size() -> PythonQt.QtCore.QSize (shared captured text) |
swap |
function | (self, other: Any) -> None |
Swaps pixmap other with this pixmap. (shared captured text) |
toImage |
function | (self) -> Any |
X.toImage() -> PythonQt.QtGui.QImage (shared captured text) |
transformed |
function | (self, arg__1: Any, mode: Any) -> Any |
X.transformed(arg__1, mode) -> PythonQt.QtGui.QPixmap (shared captured text) |
trueMatrix |
function | (self, m: Any, w: int, h: int) -> Any |
X.trueMatrix(m, w, h) -> PythonQt.QtGui.QMatrix (shared captured text) |
width |
function | (self) -> int |
X.width() -> int (shared captured text) |
widthMM |
function | (self) -> int |
X.widthMM() -> int (shared captured text) |
writeTo |
function | (self, arg__1: Any) -> Any |
(shared captured text) |