views:

62

answers:

2

Say I have a liner gradient as shown:

QLinearGradient linearGrad(QPointF(0, 0), QPointF(0, 100));
linearGrad.setColorAt(1, Qt::red);
linearGrad.setColorAt(0.5, Qt::yellow);
linearGrad.setColorAt(0, Qt::green);

How to get the color of the point QPointF(0, 28.5) in this gradient?

Indeed I want to have this kind of color distribution to be able to choose intermediate colors. I don't care if it is done by using QLinearGradient or something else.

A: 

QVariantAnimation has the similar functionality, and QVariantAnimation::keyValueAt can return the value you need. You may step into the code of QVariantAnimation and see how keyValueAt works.

Mason Chang
I have no idea how to use QVariantAnimation abstract class. Please, if you have en example, demonstrate it.
Narek
just use functions below as what you have done by QLinearGradient:- QVariantAnimation::setStartValue ( const QVariant - QVariantAnimation::setEndValue ( const QVariant Then get the the value at a point by - QVariantAnimation::keyValueAt ( qreal step );The issue here is, QVariantAnimation does not support QColor. I'm not sure if converting QColor to Int works or not.
Mason Chang
QVariantAnimation is an abstract class. It should be inherited and implemented.
Narek
why not try the concrete class "QPropertyAnimation"?
Mason Chang
A: 

I don't believe this is possible with QGradient. I just rolled my own code when I met this situation.

Vitor Py