我有一个QGraphicsScene和一个显示它的QGraphicsView。我需要添加一个QGraphicsItem到场景,并保持它在同一个位置,即使我滚动视图。我试图覆盖视图的scrollContentsBy()方法,如下所示,但它没有做到这一点。如何在滚动QGraphicsView时移动QGraphicsItem?
void FETimelineView::scrollContentsBy(int dx, int dy)
{
QGraphicsView::scrollContentsBy(dx, dy);
QRectF oRect = p_CatBar->rect();
p_CatBar->setPos(oRect.x() + dx, oRect.y() + dy);
}
顺便说一句,FETimelineView是我的QGraphicsView和p_CatBar的类型的QGraphicsItem的。请提前帮助,谢谢。
非常感谢。此解决方案有效。 – kasper360