Namespaces
Variants
Actions
Revision as of 04:13, 11 October 2012 by hamishwillee (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Archived:Colorize effect with the Qt graphics view framework

Jump to: navigation, search
Archived.png
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 (based on QWidget) is deprecated.
Article Metadata

Code Example
Compatibility
Platform(s): any

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

448 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved