如何在QGraphicsView中平移图像 [英] how to pan images in QGraphicsView
问题描述
我目前可以将我的图片加载到一个grahpics场景,然后再次进入一个QGraphicsViewer。
I am currently able to load my image into a grahpics scene, and then again into a QGraphicsViewer.
我能够实现缩放功能通过检测QEvent :: Wheel然后调用graphicsViews的scale()函数。
I am able to implement a zoom feature by dtecting a QEvent::Wheel and then calling the graphicsViews's scale() function.
然而,我似乎无法弄清楚如何获取泛功能工作。我基本上想要在鼠标点击图片时检测,然后将图片与鼠标一起向左,向右,向上或向下移动。
However, I can't seem to figure out how to get the pan functionality working. I basically want to detect when a mouse has clicked down on the image, and then move the image left, right, up or down along with the mouse.
现在,我基本上有一个MouseFilter类,它检测事件,并根据事件类型做不同的事情。我将该监听器附加到QGraphicsView对象
As of right now, I basically have a MouseFilter class that is detecting events, and doing different things depending on the event type. I attached that listener to the QGraphicsView object
推荐答案
QGraphicsView具有内置鼠标平移支持。设置正确的 DragMode ,它会处理其余的。您需要启用滚动条才能工作。
QGraphicsView has build-in mouse-panning support. Set correct DragMode and it will handle the rest. You do need the enable scroll bars for that to work.
这篇关于如何在QGraphicsView中平移图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!