問題描述
我目前能夠?qū)⑽业膱D像加載到 Graphics 場(chǎng)景中,然后再次加載到 QGraphicsViewer 中.
I am currently able to load my image into a grahpics scene, and then again into a QGraphicsViewer.
我可以通過檢測(cè) QEvent::Wheel 然后調(diào)用 graphicsViews 的 scale() 函數(shù)來(lái)實(shí)現(xiàn)縮放功能.
I am able to implement a zoom feature by dtecting a QEvent::Wheel and then calling the graphicsViews's scale() function.
但是,我似乎無(wú)法弄清楚如何使平移功能正常工作.我基本上想檢測(cè)鼠標(biāo)何時(shí)點(diǎn)擊了圖像,然后隨著鼠標(biāo)向左、向右、向上或向下移動(dòng)圖像.
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.
截至目前,我基本上有一個(gè) MouseFilter 類,用于檢測(cè)事件,并根據(jù)事件類型做不同的事情.我將該偵聽器附加到 QGraphicsView 對(duì)象
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 具有內(nèi)置的鼠標(biāo)平移支持.設(shè)置正確的 DragMode 它將處理其余的.您確實(shí)需要啟用滾動(dòng)條才能工作.
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.
這篇關(guān)于如何在 QGraphicsView 中平移圖像的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!