如何在 QGraphicsView 中平移图像

how to pan images in QGraphicsView(如何在 QGraphicsView 中平移图像)
本文介绍了如何在 QGraphicsView 中平移图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前能够将我的图像加载到 Graphics 场景中,然后再次加载到 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 中平移图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)