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:
{
pen.setWidth(30);
pen.setColor(Qt::red);
p.setPen(pen);
p.drawLine(event->lastPos(),event->pos());
p.end();
}
void GraphicsHairstyleItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
{
QPainter p( &backgroundImage );
QPen pen;
pen.setWidth(30);
pen.setColor(Qt::red);
p.setPen(pen);
p.drawLine(event->lastPos(),event->pos());
p.end();
}
To copy to clipboard, switch view to plain text mode
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
gradient.
setColorAt(0,
QColor::fromRgbF(1,
1,
1,
1));
gradient.
setColorAt(1,
QColor::fromRgbF(1,
1,
1,
0));
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);
To copy to clipboard, switch view to plain text mode
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
Bookmarks