I need to set transparency when my application loses focus. I also need to reset the transparency when it regains focus (from a mouse click or alt-tab or whatever)
I know how to set the transparency, so that is not the issue: setWindowOpacity(0.75);
The issue is WHEN?
I agree with Kévin Renella that there are sometimes issues with
QWidget::focusInEvent
andQWidget::focusOutEvent
. Instead, a better approach would be to implementQWidget::changeEvent()
:You can also achieve the same thing by installing an
event-filter
. See The Event System on Qt Documentation for more information.When a QFocusEvent event occurs. Just re-implement
from QWidget. Make sure to always call the super-class method before or after doing your work. i.e., (before case)
But, there are sometimes issues with
QWidget::focusInEvent
andQWidget::focusOutEvent
. See this answer for a more reliable approach.There are sometimes issues with
QWidget::focusInEvent
andQWidget::focusOutEvent
events ofQWidget
There is an alternative using
QWidget::windowActivationChange(bool state)
. True, your widget is active, false otherwise.