1 Star 0 Fork 1

andyspider/GAMCS-Lab

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
viewer.cpp 919 Bytes
一键复制 编辑 原始数据 按行查看 历史
#include <QMouseEvent>
#include <QDebug>
#include <QPixmap>
#include "viewer.h"
#include "scene.h"
Viewer::Viewer(QWidget *parent) : QGraphicsView(parent)
{
setBackgroundBrush(QPixmap(":/images/grid.png"));
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
setMouseTracking(true); // mouse track on
setDragMode(QGraphicsView::ScrollHandDrag);
setViewportUpdateMode(FullViewportUpdate);
}
void Viewer::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
{
// zoom out
scale(1.0 / scaleFactor, 1.0 / scaleFactor);
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/andyspider/GAMCS-Lab.git
git@gitee.com:andyspider/GAMCS-Lab.git
andyspider
GAMCS-Lab
GAMCS-Lab
master

搜索帮助