QGraphicsScene::itemAt()中的qtransform是什么?

what is the qtransform in QGraphicsScene::itemAt()

本文关键字:qtransform 是什么 中的 itemAt QGraphicsScene      更新时间:2023-10-16

我创建了一个自定义QGraphicsItem。覆盖boundingRect()paint()

QRectF myTile::boundingRect() const
{
  return QRectF(xPos*10, yPos*10, 10, 10);
}
void myTile::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
  QRectF rec = boundingRect();
  int gvi = value * 255;
  QColor gv(gvi, gvi, gvi, 255);
  QBrush brush(gv);
  painter->fillRect(rec, brush);
  painter->drawRect(rec);
}

然后我使用addItem()将一个项目添加到场景中。现在我想通过它的位置从现场得到它。我找到了itemAt函数。但问题是我不知道什么是const QTransform &deviceTransform。我应该为QTransform使用什么?

因为我没有在QGraphicsItem中实现任何转换。这让我很困惑。

QGraphicsItem * QGraphicsScene::itemAt ( const QPointF & position, const QTransform & deviceTransform ) const

返回指定位置上最上面的可见项,如果为0这个位置没有项目。deviceTransform是应用于视图的转换,并且需要提供场景包含忽略转换的项。这个函数在Qt 4.6中被引入。

所以我想说,如果你需要转换一些项目而忽略其他项目,你可以简单地使用默认值QTransform(),甚至更好的是QGraphicsView::transform() const

so long zai