3

I have been able to draw long transparent curves with the QPainterPath so I wont get overlapping opacity joints that would result in connecting lines between points like in Scribble. But is there a way to make a path blend its continuous transparency through out in Qt as such: enter image description here

TedMaster
  • 41
  • 8

2 Answers2

0

I suspect the most visually satisfying solution will be to render the strokes yourself. For example, the image you posted was rendered by drawing a large number of partially-transparent circles over one another. This could be optimized by rendering a large number of ellipses onto a QImage, then later drawing the pre-rendered image to save time.

Luke
  • 11,374
  • 2
  • 48
  • 61
0

With the help of this question/answer I wrote this code that does the job:

/* Start and end point. */
const QPointF start{ 0,0 };
const QPointF end{ 100,100 };

QGraphicsLineItem line{ QLine(start, end) };

/* Make the Gradient for this line. */
QLinearGradient gradient(start, end);
QColor color(123, 123, 231); //some color
color.setAlphaF(0.9); //change alpha
gradient.setColorAt(0, color);
color.setAlphaF(0.1); //change alpha again
gradient.setColorAt(1, color );

/* Set the line's pen. */
QPen pen(QBrush(gradient), 10);
line.setPen(pen);
Community
  • 1
  • 1
dani
  • 3,677
  • 4
  • 26
  • 60