Removing dotted border without setting NoFocus in Windows PyQt
- by Cryptite
There are a few questions on SO about this, all of which seem to say that the only way to remove the dotted border is to set the focusPolicy on widget/item in question to NoFocus. While this works as a temporary fix, this prevents further interaction with said widget/item in the realm of other necessary focusEvents.
Said border in question:
Here's an example of why this doesn't work.
I have a Non-Modal widget popup, think a lightbox for an image.
I want to detect a mousePressEvent outside of the widget and close the widget as a result. To do this, I should catch the focusOutEvent.
However, if a vast majority of widgets in my program are set as NoFocus (to remove the border issue), then I cannot catch the focusOutEvent because, you guessed it, they have no focus policy.
Here's another example:
I have a QTreeWidget that is subclassed so I can catch keyPressEvents for various reasons.
The QTreeWidget is also set as NoFocus to prevent the border. Because of this, however, the widget never has focus and therefore no keyPressEvents can be caught.
A workaround for this (kludgy, imo) is to use the widget's grabKeyboard class, which is dangerous if I forget to releaseKeyboard later. This is not optimal.
So then the question is, is there a way to remove this weird (mostly just ugly) dotted border without turning off focus for everything in my app? Thanks in advance!