void PlayLabel::wheelEvent(QWheelEvent *event) { if(m_bSelected) { int numDegrees = event->delta() / 8;//滚动的角度,*8就是鼠标滚动的距离 int numSteps = numDegrees / 15;//滚动的步数,*15就是鼠标滚动的角度 if(numSteps < 0) { qDebug()<<"steps is zoomout "<<numSteps<<",label id is "<<m_iResID; onBtZoomOutClicked(); } if(numSteps > 0) { qDebug()<<"steps is zoomin "<<numSteps<<",label id is "<<m_iResID; onBtZoomInClicked(); } //以下没用 if (event->orientation() == Qt::Horizontal) { scrollHorizontally(numSteps); //水平滚动 } else { scrollVertically(numSteps); //垂直滚动 } event->accept(); //接收该事件 } }
//! [0] void MyWidget::wheelEvent(QWheelEvent *event) { int numDegrees = event->delta() / 8; int numSteps = numDegrees / 15; if (event->orientation() == Qt::Horizontal) { scrollHorizontally(numSteps); } else { scrollVertically(numSteps); } event->accept(); }