qt:我想禁用为QTreeView自动设置的按键绑定 [英] qt: I would like to disable the key bindings automatically set for a QTreeView

查看:97
本文介绍了qt:我想禁用为QTreeView自动设置的按键绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PyQt4和QTreeView(尽管这可以很容易地直接应用于qt).

I am using PyQt4 and a QTreeView (although this could just as easily apply to qt directly).

现在,存在默认的键绑定,这些键绑定使用左右箭头控制分支的扩展/折叠.不幸的是,这些绑定不是理想的,我想禁用它们.我还无法弄清楚该怎么做.有谁知道如何禁用(或重新分配)QTreeView上的默认键绑定?

Right now there are default key bindings that control the expanding/collapsing of branches using the right and left arrows. Unfortunately, these bindings are not ideal and I would like to disable them. I have not been able to figure out how to do that. Does anyone know how to disable (or reassign) the default key bindings on a QTreeView?

推荐答案

有两种可能的选择: 1)重新实现QTreeView的 keyPressEvent 并检查所按下的键是否为 Qt :: Key_Up

There are two possible options for you: 1) Reimplement the keyPressEvent of QTreeView and check if the key pressed are either Qt::Key_Up or Qt::Key_Down.

2)您可以安装 eventFilter 并检查事件是否是 QEvent :: KeyPress ,并且该键与 Qt :: Key_Up

2) You could install an eventFilter and check if the event is a QEvent::KeyPress and that the key matches either Qt::Key_Up or Qt::Key_Down.

我不了解PyQt,所以我不能用Python提供代码,但我希望我已经足够清楚了.

I don't know PyQt so I can't give you code in Python, but I hope I have been clear enough.

这篇关于qt:我想禁用为QTreeView自动设置的按键绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆