PDA

View Full Version : How to get color of pixel or point?



qt_developer
28th June 2012, 18:06
Hi all,

I have a QWidget with this style sheet:

background: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 rgb(0, 0, 0), stop: 1 rgb(255, 255, 255));

How can I get the color in each point?

Regards.

mvuori
28th June 2012, 19:06
First Google hit for 'qwidget get pixel' is http://www.qtcentre.org/threads/30966-Get-QWidget-pixel-color-below-mouse-Cursor and should show you how.

qt_developer
28th June 2012, 19:14
I have used this code and seems that works fine:



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


Thanks!