Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) Qt QColor

 

QColor is a Qt class for a color.

 

The code below, adapted from Qt example 1: moving a sprite over a background in 2D, shows how to set the color lime to the color made transparent.

 

#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);
  }
};

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict