QT:我需要通过qgraphicscene将图像的坐标添加到QGraphicsView

QT:我需要通过qgraphicscene将图像的坐标添加到QGraphicsView,qt,qgraphicsview,qgraphicsscene,Qt,Qgraphicsview,Qgraphicsscene,当我将小图像添加到QGraphicsView中时,是否有方法获取图像像素的坐标?我在自定义类QGraphicsView中使用了rubberband,但我只能获取QGraphicsView坐标。我想您希望从给定位置获取像素。假设给定位置来自鼠标位置 例如,从QGraphicsView继承的类: MyView::MyView( QWidget *parent=0 ) : QGraphicsView(parent) { setScene( new QGraphicsScene( this )

当我将小图像添加到QGraphicsView中时,是否有方法获取图像像素的坐标?我在自定义类QGraphicsView中使用了rubberband,但我只能获取QGraphicsView坐标。

我想您希望从给定位置获取像素。假设给定位置来自鼠标位置

例如,从QGraphicsView继承的类:

MyView::MyView( QWidget *parent=0 ) :  QGraphicsView(parent)
{
    setScene( new QGraphicsScene( this ) );
    this->scene()->addPixmap(QPixmap::fromImage(this->image)); // this->image is a QImage
}
然后,实现鼠标事件

void MyView::mouseMoveEvent( QMouseEvent* event )
{
    QPointF pos =  mapToScene( event->pos() );
    QRgb rgb = this->image.pixel( ( int )pos.x(), ( int )pos.y() );
}

“获取图像像素的坐标”到底是什么意思?你的意思是你想要屏幕坐标,图像相对于原始图像的位置,以像素为单位,还是其他什么?对不起,现在你提醒我,这真的不清楚。实际上我需要的是原始图像的坐标,而不是图形视图坐标。谢谢。我需要这样的东西。它起作用了。如果我没有要求更多,rubberband能否仅限于图像区域?