PyQt5 - Get the pixel color inside a QWidget
I made a QWidget and inside I made some other items like QLabels which display images.
Consider what is inside that parent Widget I was trying to get the color where I would click.
Searching I found this thread but it is a bit old and I am not able to translate it to Python. as I cant read C++.
thread:
https://www.qtcentre.org/threads/496...pixel-or-point
code:
Code:
QColor color
(image.
pixel(0,
1));
How would this translate to PyQt5 if it is the correct answer?
Re: PyQt5 - Get the pixel color inside a QWidget
Don't double post, please.
QPixmap::grabWidget() has been deprecated and is no longer in Qt5, so this code wouldn't compile even in C++. However, there is an alternative. I am not too familiar with PyQt5, but the code should look something like this (where "widget" the is one you want the pixels from):
Code:
pixMap
= QPixmap( widget.
width(), widget.
height() )widget.render( pixMap )
image = pixMap.toImage()
color = image.pixelColor( 0, 0 )