Git Product home page Git Product logo

Comments (1)

pezy avatar pezy commented on June 12, 2024

QWheelEvent::delta () 正是该问题的答案。

该函数返回滚轮滚过的一个距离,正好是滚轮旋转角度的8倍。正值表示往滚动,负值表示往滚动。

一般鼠标普遍以15度为一步,这种情况下,delta 的返回值是120 (8*15) 的整数倍。(120 units * 1/8 = 15 degrees.)

然而,对于一些高分辨率的鼠标来说,delta值可能是小于 120 的(小于15度)。 要支持这种可能性, 你要么让delta的值自加至120后作为一次滚动, 要么就每滚动一下就响应一次wheelEvent事件。

文档示例:

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();
 }

from qtlab.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.