[Interest] Qt::GlobalColor to pixel value

Christoph Feck cfeck at kde.org
Tue Mar 19 19:31:36 CET 2019


On 03/19/19 19:25, Jason H wrote:
> What is the simplest way to go from:
>
> QList<QColor> pallette {Qt::black,Qt::red,Qt::darkRed,Qt::green,Qt::darkGreen,Qt::blue,Qt::darkBlue,Qt::cyan,Qt::darkCyan,Qt::magenta,Qt::darkMagenta,Qt::yellow,Qt::darkYellow};
>
> To a pixel QRgb?
>
> image.setPixel(x,y, pallette[5]);
>
> The .toRgb() of QColor does not actually return a QRgb, instead it converts the color to RGB representation internally.
>
> I've hacked this:
> uint toRgb(const QColor &c) {
> 	return qRgb(c.red(), c.blue(), c.green());
> }
>
> image.setPixel(x,y, toRgb(pallette[5]));
>
> but it seems so obtuse.
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest
>


https://doc.qt.io/qt-5/qcolor.html#rgb

or use https://doc.qt.io/qt-5/qimage.html#setPixelColor


More information about the Interest mailing list