PDA

View Full Version : PyQt5 - Get the pixel color inside a QWidget



noob_user
15th September 2020, 04:59
I was trying to get the color of a pixel inside a QWidget I made. However I have some questions because I was learnning Python and not C++.

I came accross this post:
https://www.qtcentre.org/threads/49693-How-to-get-color-of-pixel-or-point

and they say the solution would be this:

QPixmap qPix = QPixmap::grabWidget(ui->myWidget);
QImage image(qPix.toImage());
QColor color(image.pixel(0, 1));

How would it translate to PyQt5 if this is the correct answer?