Removing dotted border without setting NoFocus in Windows PyQt
Posted
by
Cryptite
on Stack Overflow
See other posts from Stack Overflow
or by Cryptite
Published on 2012-03-20T22:09:55Z
Indexed on
2012/03/31
17:29 UTC
Read the original article
Hit count: 224
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!
© Stack Overflow or respective owner