olidem
5th March 2009, 18:12
Hi!
I derived from QGraphicsItem and I would like to be able to perfom some freehand painting.
For normal pens, this is not a problem, I manage a QImage and in my mouseReleaseEvent, I draw lines from one to the next event position:
void GraphicsHairstyleItem::mouseReleaseEvent(QGraphics SceneMouseEvent * event)
{
QPainter p( &backgroundImage );
QPen pen;
pen.setWidth(30);
pen.setColor(Qt::red);
p.setPen(pen);
p.drawLine(event->lastPos(),event->pos());
p.end();
}
The question now is:
How can I use a pen which is "diffuse" at the boundary, ie. a radial gradient whose alpha-component goes to 0 at the outside ???
I know that I could get a QRadial Gradient as QBrush like
QRadialGradient gradient(15, 15, 15, 15, 15);
gradient.setColorAt(0, QColor::fromRgbF(1, 1, 1, 1));
gradient.setColorAt(1, QColor::fromRgbF(1, 1, 1, 0));
QBrush b(gradient);
this does not work and as far as I know, brushes are used for filling, not for the outlines.
Appreciate any help!
Thanks a lot!!!
Olli
I derived from QGraphicsItem and I would like to be able to perfom some freehand painting.
For normal pens, this is not a problem, I manage a QImage and in my mouseReleaseEvent, I draw lines from one to the next event position:
void GraphicsHairstyleItem::mouseReleaseEvent(QGraphics SceneMouseEvent * event)
{
QPainter p( &backgroundImage );
QPen pen;
pen.setWidth(30);
pen.setColor(Qt::red);
p.setPen(pen);
p.drawLine(event->lastPos(),event->pos());
p.end();
}
The question now is:
How can I use a pen which is "diffuse" at the boundary, ie. a radial gradient whose alpha-component goes to 0 at the outside ???
I know that I could get a QRadial Gradient as QBrush like
QRadialGradient gradient(15, 15, 15, 15, 15);
gradient.setColorAt(0, QColor::fromRgbF(1, 1, 1, 1));
gradient.setColorAt(1, QColor::fromRgbF(1, 1, 1, 0));
QBrush b(gradient);
this does not work and as far as I know, brushes are used for filling, not for the outlines.
Appreciate any help!
Thanks a lot!!!
Olli