axadiw
15th December 2010, 17:43
Hi,
I've tried to apply QGraphicsBlurEffect to my QGraphicsPixmapItem, but after doing so, my item disappears form the scene!
Thats the code i've used:
Player* player(playerImage);
scene.addItem(player);
QGraphicsBlurEffect* blur = new QGraphicsBlurEffect;
player->setGraphicsEffect(blur);
here's Player class:
player.h
#ifndef PADDLE_H
#define PADDLE_H
#include <QGraphicsItem>
class Player : public QGraphicsPixmapItem
{
public:
Player(QPixmap* _image);
QRectF boundingRect() const;
QPainterPath shape() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QPixmap image;
};
#endif // PADDLE_H
player.cpp
#include <QPainter>
#include "player.h"
Player::Player(QPixmap* _image)
{
image = _image->scaled(QSize(100,100),Qt::KeepAspectRatio);
}
QRectF Player::boundingRect() const
{
return image.rect();
}
QPainterPath Player::shape() const
{
QPainterPath path;
path.addRect(image.rect());
return path;
}
void Player::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
painter->drawPixmap(-image.rect().width(),-image.rect().height(),image);
}
What should I do?
I've tried to apply QGraphicsBlurEffect to my QGraphicsPixmapItem, but after doing so, my item disappears form the scene!
Thats the code i've used:
Player* player(playerImage);
scene.addItem(player);
QGraphicsBlurEffect* blur = new QGraphicsBlurEffect;
player->setGraphicsEffect(blur);
here's Player class:
player.h
#ifndef PADDLE_H
#define PADDLE_H
#include <QGraphicsItem>
class Player : public QGraphicsPixmapItem
{
public:
Player(QPixmap* _image);
QRectF boundingRect() const;
QPainterPath shape() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QPixmap image;
};
#endif // PADDLE_H
player.cpp
#include <QPainter>
#include "player.h"
Player::Player(QPixmap* _image)
{
image = _image->scaled(QSize(100,100),Qt::KeepAspectRatio);
}
QRectF Player::boundingRect() const
{
return image.rect();
}
QPainterPath Player::shape() const
{
QPainterPath path;
path.addRect(image.rect());
return path;
}
void Player::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
painter->drawPixmap(-image.rect().width(),-image.rect().height(),image);
}
What should I do?