Skip to content

Latest commit

 

History

History
46 lines (27 loc) · 1.74 KB

CppQBitmap.md

File metadata and controls

46 lines (27 loc) · 1.74 KB

 

 

 

 

 

 

QBitmap is a Qt class used for masking/transparency in QPixmap. QBitmap is a class for containing monochrome (that is: each pixel is either on or off) images, instead of the colored Windows bitmaps.

 

The code below, adapted from Qt example 1: moving a sprite over a background in 2D, shows how to add transparency to a QPixmap.

 


#include <QGraphicsPixmapItem> struct Sprite : public QGraphicsPixmapItem {   Sprite(     const std::string& filename,     const QColor& transparency_color = QColor(0,255,0)) //Lime green   {     QPixmap pixmap(filename.c_str());     const QBitmap mask = pixmap.createMaskFromColor(transparency_color);     pixmap.setMask(mask);     this->setPixmap(pixmap);   } };