Archived:Transparent QPixmap picture
Archived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.
Qt Quick should be used for all UI development on mobile devices. The approach described in this article (using C++ for the Qt app UI) is deprecated.
Qt Quick should be used for all UI development on mobile devices. The approach described in this article (using C++ for the Qt app UI) is deprecated.
Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic, Nokia N900
Compatibility
Platform(s): Qt
Article
Keywords: QPixmap, QPainter
Created: tepaa
(21 Oct 2009)
Last edited: hamishwillee
(11 Oct 2012)
Contents |
Overview
This example shows how to change a QPixmap picture to transparent.
Preconditions
- Qt is installed on your platform.
- Download Qt release from here: [1]
- Qt on Maemo can be found here: Qt4 Maemo port
Header
private:
// Original pixmap
QPixmap pixmap;
Source
// Create new picture for transparent
QPixmap transparent(pixmap.size());
// Do transparency
transparent.fill(Qt::transparent);
QPainter p(&transparent);
p.setCompositionMode(QPainter::CompositionMode_Source);
p.drawPixmap(0, 0, pixmap);
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
// Set transparency level to 150 (possible values are 0-255)
// The alpha channel of a color specifies the transparency effect,
// 0 represents a fully transparent color, while 255 represents
// a fully opaque color.
p.fillRect(transparent.rect(), QColor(0, 0, 0, 150));
p.end();
// Set original picture's reference to new transparent one
pixmap = transparent;
Postconditions
The picture is now transparent.


(no comments yet)