desch
22nd May 2008, 09:26
Hello all,
I try to make a classic color scale using two colors; the aim is to enter the color start and the color end and the QLinearGradient will calculate all colours for me ; So I can get it using QImage::colorTable();
I didn't succeed so I send you a piece of my code:
QColor start = Qt::red;
QColor stop = Qt::green;
QLinearGradient linearGrad(QPointF(100,100), QPointF(200, 200));
linearGrad.setColorAt(0, start);
linearGrad.setColorAt(1, stop);
// create image and fill it with gradient
QImage image(100, 100, QImage::Format_ARGB32);
QPainter painter(&image);
painter.fillRect(image.rect(),linearGrad);
// get all colors from the table
QVector<QRgb> tmpColorVec = image.colorTable();
qDebug(QString::number(tmpColorVec.count()).toAsci i());
for (int i = 0 ; i < tmpColorVec.count(); ++i)
{
QRgb color = tmpColorVec.at(i);
qDebug("R = " + QString::number(qRed(color)).toAscii() +
" G = " + QString::number(qGreen(color)).toAscii() +
" B = " + QString::number(qBlue(color)).toAscii());
}
Questions : What I do wrong?
What should I do?
Thanks to all
David
I try to make a classic color scale using two colors; the aim is to enter the color start and the color end and the QLinearGradient will calculate all colours for me ; So I can get it using QImage::colorTable();
I didn't succeed so I send you a piece of my code:
QColor start = Qt::red;
QColor stop = Qt::green;
QLinearGradient linearGrad(QPointF(100,100), QPointF(200, 200));
linearGrad.setColorAt(0, start);
linearGrad.setColorAt(1, stop);
// create image and fill it with gradient
QImage image(100, 100, QImage::Format_ARGB32);
QPainter painter(&image);
painter.fillRect(image.rect(),linearGrad);
// get all colors from the table
QVector<QRgb> tmpColorVec = image.colorTable();
qDebug(QString::number(tmpColorVec.count()).toAsci i());
for (int i = 0 ; i < tmpColorVec.count(); ++i)
{
QRgb color = tmpColorVec.at(i);
qDebug("R = " + QString::number(qRed(color)).toAscii() +
" G = " + QString::number(qGreen(color)).toAscii() +
" B = " + QString::number(qBlue(color)).toAscii());
}
Questions : What I do wrong?
What should I do?
Thanks to all
David