如何使用 QGraphicsView 的 translate() 函数? [英] How to use the QGraphicsView's translate() function?
问题描述
这里我有一个场景和一个关联的视图,然后我在场景坐标中有一个位置.我想用这个位置设置视口的中心.我该怎么做?我尝试使用 translate() 函数但它不起作用?
here i have a scene and a associated view ,then i hava a position in the scene coordinates.I want to set the center of the viewport with the position.How can i do it? I try to use the translate() function but it didn't work?
view->translate(10, 10);
视口应该随着 delta x 10 和 delta y 10 移动,但它不起作用!
The viewport should move with the delta x 10, and delta y 10, but it didn't work!
推荐答案
需要将图形视图的变换锚点模式设置为NoAnchor.
You need to set the transformation anchor mode of the graphics view to NoAnchor.
setTransformationAnchor(QGraphicsView::NoAnchor);
这可以防止图形视图如其他锚点模式(AnchorViewCenter、AnchorUnderMouse)所预期的那样撤消平移.
This prevents the graphics view from undoing the translation as expected by the other anchor modes (AnchorViewCenter, AnchorUnderMouse).
这篇关于如何使用 QGraphicsView 的 translate() 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!