×
Namespaces

Variants
Actions
Revision as of 09:23, 28 June 2012 by hamishwillee (Talk | contribs)

Archived:Shadow 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 (C++ for the Qt UI) is deprecated.

This article shows how to use QGraphicsShadowEffect to apply a shadow effect to Graphics Items. none‎

Article Metadata
Compatibility
Platform(s): any
Symbian
Article
Keywords: QGraphicsShadowEffect
Created: gnuton (24 Dec 2010)
Last edited: hamishwillee (28 Jun 2012)

Code

This is a minimal application which creates a shadow for a QGraphicsPixmap using the QGraphicsShadowEffect.

#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"));
 
QGraphicsDropShadowEffect shadow;
shadow.setBlurRadius(100.0);
shadow.setColor(Qt::red);
shadow.setOffset(0,0);
p->setGraphicsEffect(&shadow);
 
view.show();
return a.exec();
}

The QGraphicsDropShadowEffect class provides a drop shadow effect. A drop shadow effect renders the source with a drop shadow. The color of the drop shadow can be modified using the setColor() function. The drop shadow offset can be modified using the setOffset() function and the blur radius of the drop shadow can be changed with the setBlurRadius() function.

Source code

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

94 page views in the last 30 days.