0

This seems trivial, but can't find a solution. I need to read a color of certain x,y point on QGraphicsScene. Something like graphScen->colorAt(x,y);

Ko Cour
  • 929
  • 2
  • 18
  • 29
  • See http://stackoverflow.com/questions/3602152/how-to-draw-a-qpoint-on-a-qgraphicsview-scene – Mihai8 Feb 24 '13 at 10:59
  • That question can't be answered for a QGraphicsScene before it's painted in a QGraphicsView. The scene manages yet unpainted items, with float coordinates. The actual painting needs to be done by a paint device, i.e. the QGraphicsView. Only then QGraphicsItem::paint is called and does the actual painting. – Frank Osterfeld Feb 25 '13 at 07:10

1 Answers1

0

A QGraphivsScene doesn't have the knowledge of the colors on points, and it's not really trivial (you have transformations both on scenes and items). what you could do is to access the pixmap of the rendered scene and access the pixel information there.

QPixmap paintDevice(sceneBoundingRect());
QPainter painter(&paintDevice);
graphScen->render(painter);
// Now you have the pixmap, get the pixel information.
QImage pixels = paintDevice.toImage();
QRgb colorAt = pixels.pixel(x,y);

Done.

Tomaz Canabrava
  • 2,320
  • 15
  • 20