First of all, you must implement mouseMoveEvent in your custom element. In this function, you can easily get the mouse position calling the pos function. You can get the rgb value if you convert the pixmap element to an image and call the pixel function. You should consider storing the QImage variable as a member to avoid multiple conversions. Finally, you must emit your own signal. Code example:
void MyPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) { QPointF mousePosition = event->pos(); QRgb rgbValue = pixmap().toImage().pixel(mousePosition.x(), mousePostion.y()); emit currentPositionRgbChanged(mousePosition, rgbValue); }
Please note that QGraphicsItems does not inherit from QObject , therefore, signals / slots are not supported by default. You must inherit from QObject . This is what QGraphicsObject does. Last but not least, I would suggest enabling mouse tracking on your QGraphicsView
source share