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!
Asked
Active
Viewed 1,445 times
0
-
That does not make Sense. The Item that has focus recieves keypresses. Your item never has focus… – Chronial Mar 02 '12 at 22:34
-
From everything I've read so far, the only way to remove the ugly (Windows?) dotted border that some items receive when focused is to set the focus policy as Qt.NoFocus. I understand this is preventing the keypress events from naturally occurring, but thus far I'm unsure how to remove the dotted border focus effect any other way. – Cryptite Mar 06 '12 at 19:52
1 Answers
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

jesterjunk
- 2,342
- 22
- 18

Chronial
- 66,706
- 14
- 93
- 99
-
If I pair this with the itemSelectionChanged() signal in my QTreeWidget, then I can pretty safely grab and release the keyboard only when needed (ie only when there are widgetitems selected). Seems kludgy, but it works. Thanks Chronial. – Cryptite Mar 06 '12 at 20:02
-
I am pretty sure you can also change the style of the element, either by changing the css or by rendering stuff yourself. What you want to do is just plain wrong and *will* break stuff (screenreaders for blind people for example). – Chronial Jun 06 '12 at 13:40