Results 1 to 4 of 4

Thread: color table with QGradient and QImage

  1. #1
    Join Date
    Jul 2006
    Posts
    37
    Thanks
    6
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default color table with QGradient and QImage

    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:
    Qt Code:
    1. QColor start = Qt::red;
    2. QColor stop = Qt::green;
    3.  
    4.  
    5. QLinearGradient linearGrad(QPointF(100,100), QPointF(200, 200));
    6. linearGrad.setColorAt(0, start);
    7. linearGrad.setColorAt(1, stop);
    8.  
    9. // create image and fill it with gradient
    10. QImage image(100, 100, QImage::Format_ARGB32);
    11. QPainter painter(&image);
    12. painter.fillRect(image.rect(),linearGrad);
    13.  
    14. // get all colors from the table
    15. QVector<QRgb> tmpColorVec = image.colorTable();
    16. qDebug(QString::number(tmpColorVec.count()).toAscii());
    17.  
    18. for (int i = 0 ; i < tmpColorVec.count(); ++i)
    19. {
    20. QRgb color = tmpColorVec.at(i);
    21. qDebug("R = " + QString::number(qRed(color)).toAscii() +
    22. " G = " + QString::number(qGreen(color)).toAscii() +
    23. " B = " + QString::number(qBlue(color)).toAscii());
    24. }
    To copy to clipboard, switch view to plain text mode 

    Questions : What I do wrong?
    What should I do?

    Thanks to all

    David

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: color table with QGradient and QImage

    The colour table is only available in 8 bit (or less) images. There is no concept of colour table for 24+ deep images. I explained it about a week ago in some other thread.

  3. #3
    Join Date
    Jul 2006
    Posts
    37
    Thanks
    6
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: color table with QGradient and QImage

    Ok Thanks,

    But Is there a basic way to make a color scale suing QGradient and a kind of container to grab colors results ?

    David

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: color table with QGradient and QImage

    I think it will be much quicker if you calculate the colours yourself. The transition is linear so this shouldn't pose a problem, just add a calculated step to each of the colour components.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.