×
Namespaces

Variants
Actions

Archived:Colorize 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 QWidget) is deprecated.

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

Introduction

This article shows how to use the colorize effect using Qt's QGraphicsColorizeEffect. Qt Graphics view framework offers a convenient way to apply graphics effects to Graphics Items.

Qt-GraphicsEffect-Colorize.jpg

Code

This is a minimal application which colors a QGraphicsPixmap using the QGraphicsColorizeEffect. The QGraphicsColorizeEffect class provides a colorize effect. The color can be modified using the setColor() function. setStrength() changes the colorize strength property.


#include <QtGui/QApplication>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsPixmapItem>
#include <QGraphicsEffect>
 
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGraphicsView view;
view.setScene(new QGraphicsScene);
 
QGraphicsPixmapItem *p = view.scene()->addPixmap(QPixmap(":/meditate.png"));
 
QGraphicsColorizeEffect colorize;
colorize.setColor(QColor(Qt::red)); //Default value is blue
colorize.setStrength(0.5); //Default value is 1.0
p->setGraphicsEffect(&colorize);
 
view.show();
return a.exec();
}

Source code

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