我有一個應用程序,可以在Qt Creator中使用鼠標滾輪來處理縮放。在Qt中按下鼠標滾輪時的平移C++
CPP
void QNodeView::wheelEvent(QWheelEvent* event) {
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
// Scale the view/do the zoom
double scaleFactor = 1.15;
if(event->delta() > 0) {
// Zoom in
scale(scaleFactor, scaleFactor);
} else {
// Zooming out
scale(1.0/scaleFactor, 1.0/scaleFactor);
}
}
這是
protected:
//Take over the interaction
virtual void wheelEvent(QWheelEvent* event);
如何添加鼠標中鍵可進行平移的能力,與被按下的用戶拖動頭文件 ^h光標?
如果需要的話,我可以發佈項目代碼。 感謝
項目文件的鏈接(Qt Creator的項目)
https://www.dropbox.com/s/gbt4qqtdedltxek/QNodesEditor-master_01.zip?dl=0
覆蓋mousePressEvent(),mouseMoveEvent(),和mouseReleaseEvent(),和內部的每個那些試驗的事件 - >按鈕()== Qt的:: MiddleButton –