Comments (1)
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)
- 如何制作一个自适应缩放的坐标轴 HOT 18
- 如何计算字体的像素信息(长度?宽度?) HOT 1
- 如何在 Xcode 中进行 Qt 开发? HOT 1
- QWidget 那么多获取边框的方法有啥区别?该怎么用? HOT 1
- 如何在QPainter里用鼠标滑动一根线。 HOT 2
- 如何变换鼠标的指针形状?都有哪些指针形状? HOT 1
- 能不能对QPainter中的线条增加右键菜单?并通过菜单修改颜色或删除? HOT 1
- 通过 QLinearGradient 进行线性插值之后,如何获取中间某位置的特定颜色? HOT 14
- 如何设置界面风格? HOT 2
- vs2010下无法创建Translation File HOT 1
- 想学习下Qt,讨论一下关注点. HOT 16
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qtlab.