我有一个应用程序,可以在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 –