×
Namespaces

Variants
Actions

Archived:Transparent QPixmap picture

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: 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.

Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic, Nokia N900
Compatibility
Platform(s): Qt
Symbian
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.


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.


See also

This page was last modified on 11 October 2012, at 04:15.
159 page views in the last 30 days.
×