一.前言
突发奇想,滚轮事件既然能被捕获,那能不能被确定滚轮的方向呢???
二.过程
不管三七二十一,先把event打印一下
滚动过程中发现angleDelta有变化,并且是向前滚为正,向后滚为负,故猜测应该是angleDelta来体现的
后面查阅文档:
Returns the distance that the wheel is rotated, in eighths of a degree. A positive value indicates that the wheel was rotated forwards away from the user; a negative value indicates that the wheel was rotated backwards toward the user.
大概的意思就是,这个值是返回滚轮被旋转的距离,值表示滚轮向前旋转,远离用户;负值表示滚轮向后旋转向用户
至此,就可以确定滚动的方向了
void Widget::wheelEvent(QWheelEvent *event)
{
qDebug()<<QDateTime::currentDateTime().toString("[yyyy-MM-dd HH:mm:ss.zzz]")<<event;
if(event->angleDelta().y()>0)
{
qDebug()<<"向前滚";
// 放大业务逻辑
}
else
{
qDebug()<<"向后滚";
// 缩小业务逻辑
}
}