[Interest] Qt::GlobalColor to pixel value

Jason H jhihn at gmx.com
Tue Mar 19 19:25:17 CET 2019


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.



More information about the Interest mailing list