Archived:Colorize effect with the Qt graphics view framework
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.
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
Source file: Media:GraphicsEffect-Colorize.zip
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.
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
- You can download the code from here: Media:GraphicsEffect-Colorize.zip



(no comments yet)