qt: I would like to disable the key bindings automatically set for a QTreeView

丶灬走出姿态 提交于 2020-01-04 05:17:59

问题


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

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:


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) 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.

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



来源:https://stackoverflow.com/questions/4130971/qt-i-would-like-to-disable-the-key-bindings-automatically-set-for-a-qtreeview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!