How to read a color of a pixel on a Widget?
Is there any way to read a color of a pixel on a widget? i.e. read the color of a pixel right under my mouse pointer. I've been searching in various places and I'm slowly starting to think that QT doesn't support such functionality, but I might just be looking at the wrong place. Please give some advice to a newbie!!! :)
Re: How to read a color of a pixel on a Widget?
you can use QPixmap::grabWidget(), convert it to QImage and then use QImage::pixel().
Re: How to read a color of a pixel on a Widget?
I just solved it using a similar technique, but thanks for the reply!!! :D
Code:
this->render(&pixmap);
QRgb pix = img.pixel(10,10);
std::cout << "Red : " << qRed(pix) << std::endl;
std::cout << "Green : " << qGreen(pix) << std::endl;
std::cout << "Blue : " << qBlue(pix) << std::endl;
Re: How to read a color of a pixel on a Widget?
It should be faster if you open the painter directly on the QImage object instead of the pixmap.
Re: How to read a color of a pixel on a Widget?
If you are using the mouse - do it through QMouseEvent with QEvent::MouseMove. So you will get theright coordinates and then call QImage through QPainter. That is faster.
Re: How to read a color of a pixel on a Widget?
Quote:
Originally Posted by
Tanuki-no Torigava
So you will get theright coordinates and then call QImage through QPainter. That is faster.
Only if you cache the image, because rendering the image every time you move the mouse is damn slow!