PDA

View Full Version : Get QWidget pixel color below mouse Cursor



^NyAw^
24th May 2010, 12:51
Hi,

Is there anyway to get the color of a pixel on a QWidget on a known pixel position?

Thanks,

Lykurg
24th May 2010, 12:58
See QPixmap::grabWidget() with a proper second argument (or QPixmap::grabWindow() when it is outside your app) and then use QPixmap::toImage() and finally get the color using QImage::pixel().

^NyAw^
24th May 2010, 13:01
Hi,

Thanks, but is a slow solution. I need a faster way to get it.

Lykurg
24th May 2010, 13:27
Did your widget change a lot? if not, you can cache a QImage inside the paint method and use that for determinating the color at a specific point. Beside that I don't know a solution for your problem with Qt. You can of course use the operating API to get that information.

^NyAw^
24th May 2010, 17:17
Hi,

Thanks Lykurg,



Did your widget change a lot?

Yes, it changes very fast as it shows images captured from a camera. Before you tell me to get the image pointer, I need to tell you that as there is a thread that emits signals with image pointers, this pointers can point on deleted memory. Sending copy images slows down my application a lot.

Will take a look to use OS specific API to get it. I think that on Windows I can get the HDC pointer to get this information.

Thanks,