Catching a keyPressEvent in a QTreeWidget with no

2019-09-12 01:36发布

问题:

So I desired to remove the ugly dotted border on my QTreeWidget by setting NoFocus on the focus policy. Now I need to catch keyPressEvents, but the focus policy is preventing that. Any ideas how one might circumvent this catch 22 so that I can catch a delete key press for easy item deletion? Thanks in advance!

回答1:

I assume you are trying to do something that you really shouldn't, but anyways …

This is the way to go: http://doc.qt.io/qt-4.8/qwidget.html#grabKeyboard