問題描述
我目前能夠將我的圖像加載到 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 中平移圖像的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!