The "Elastic Nodes Example" provided me with a simpler way to draw a ball with a light spot and a smooth transition to the darker parts.
In that example - Node:: paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) - QRadialGradient is used:
QRadialGradient gradient(-3, -3, 10);
To copy to clipboard, switch view to plain text mode
My problem is solved, and I think to use QRadialGradient would also work to draw an image like the one in the "Gradients" example. Interestingly though, I see in that example - in void GradientRenderer:aint(QPainter *p) - a QGradient variable is declared and used:
void GradientRenderer
:: paint(QPainter *p
) {
// and then farther down in the function:
p->setBrush(g);
void GradientRenderer:: paint(QPainter *p)
{
QPolygonF pts = m_hoverPoints->points();
QGradient g;
// and then farther down in the function:
p->setBrush(g);
To copy to clipboard, switch view to plain text mode
When I tried to do the same, it crashed, because I left out this part:
if (m_gradientType == Qt::LinearGradientPattern) {
} else if (m_gradientType == Qt::RadialGradientPattern) {
} else {
QLineF l
(pts.
at(0), pts.
at(1));
qreal angle
= l.
angle(QLineF(0,
0,
1,
0));
if (l.dy() > 0)
angle = 360 - angle;
}
if (m_gradientType == Qt::LinearGradientPattern) {
g = QLinearGradient(pts.at(0), pts.at(1));
} else if (m_gradientType == Qt::RadialGradientPattern) {
g = QRadialGradient(pts.at(0), qMin(width(), height()) / 3.0, pts.at(1));
} else {
QLineF l(pts.at(0), pts.at(1));
qreal angle = l.angle(QLineF(0, 0, 1, 0));
if (l.dy() > 0)
angle = 360 - angle;
g = QConicalGradient(pts.at(0), angle);
}
To copy to clipboard, switch view to plain text mode
g is changed to a QLinearGradient or a QRadialGradient or a QConicalGradient.
Bookmarks