Archived:Opacity effect with the Qt graphics view framework

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 (based on C++ for the Qt UI) is deprecated.

This article shows how to use the opacity effect using the Qt QGraphicsOpacityEffect.

Article Metadata
Code ExampleCompatibility
Platform(s): any
Keywords: QGraphicsOpacityEffect
Created: gnuton (24 Dec 2010)
Last edited: hamishwillee (11 Oct 2012)


Qt Graphics view framework offers a convenient way to apply graphics effects to Graphics Items.



This is a minimal application which changes the opacity of a QGraphicsPixmap using the QGraphicsOpacityEffect.

The item opacity can be set with two methods:

  • setOpacity(): it accepts values from 0.0 (image completely transparent) to 1.0.
  • setOpacityBrush(): it supports gradients or masks

The following example shows how to use a mask to set the opacity of the given pixmap item.

#include <QtGui/QApplication>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsEffect>
#include <QBrush>
#include <QBitmap>
#include <QGraphicsPixmapItem>
int main(int argc, char *argv[])
QApplication a(argc, argv);
QGraphicsView view;
view.setScene(new QGraphicsScene);
QGraphicsPixmapItem *p = view.scene()->addPixmap(QPixmap(":/cappella_sistina.jpg"));
QGraphicsOpacityEffect opacity;
return a.exec();

Source code

You can download the code from here: Media:GraphicsEffect-Opacity.zip

This page was last modified on 11 October 2012, at 01:14.
72 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.