在 QListWidget 上自定义 PyQt 多点触控平移手势
我在编写一个简单的记事本应用程序来自学基本的 Python/PyQt 时遇到问题。 具体来说,我想知道如何更改 QListWidget 上的多点触控平移手势灵敏度。
就像现在一样,当我用两根手指上下拖动时,似乎列表随着我用手指移动的每个像素而向上/向下移动一步。这不是我自己实现的,它似乎对于列表小部件来说是开箱即用的,
我希望移动模仿我手指的速度,即每个 x*height_of_item_in_pixels 向上/向下移动小部件项目。在不对手势系统进行重大黑客攻击的情况下,这是否可行? 我该怎么办呢?
我正在使用 PyQt 4.8.3 和 Python 2.6
I'm having a problem with a simple Notepad application I'm writing to teach myself basic Python/PyQt.
Specifically, I want to know how to change the multi-touch pan gesture sensitivity on a QListWidget.
As it is now, when I drag up and down with 2 fingers, it seems like the list is moving up/down one step for each pixel I move with my fingers. This is nothing I've implemented myself, it seems to work out of the box for list widgets
I want the movement to mimic the speed of my fingers i.e one move up/down of the widget items for every x*height_of_item_in_pixels. Is this doable without major hacking into the gesture system?
How would I go about this?
I'm using PyQt 4.8.3 with Python 2.6
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有点晚了,但也许我可以帮助其他偶然发现这个问题的人:
解决方案是将
QListWidget
的滚动模式设置为ScrollPerPixel
(而不是默认的 < code>ScrollPerItem):一个最小的示例:
注意:此示例还演示了如何使用鼠标实现平移,这对于在没有触摸屏的设备上进行测试非常有用。此外,除了默认的两指平移手势之外,鼠标平移设置还支持单指平移(至少在 Windows 上,在 Surface Pro 平板电脑上进行了测试)。
Quite a bit late, but maybe I can help others who stumble upon this question:
The solution is to set the scroll mode for the
QListWidget
toScrollPerPixel
(instead of the defaultScrollPerItem
):A minimal example:
Note: This example also shows how to implement panning using the mouse, which is useful for testing on devices without touch-screen. Moreover, the mouse pan setting also enables one-finger pan, in addition to the default two-finger pan gesture (at least on Windows, tested on Surface Pro tablet).
此功能很可能存在,因为多点触控事件被操作系统解释为某种类型的滚动,并且 QT 正在接收滚动操作,而不是直接接收多点触控操作。
More than likely this functionality exists because the multitouch event is being interpreted by your operating system as a scroll of some type and QT is recieving the scroll action, rather than the multitouch action directly.