问题
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