In some cases on Windows platform, isActive() called on QWidget returns true, when, obviously, it cannot be active.
For example, my app doing much work on GUI thread and shows window with some delay after launch. If I launch app and switch to another application before app shows main window, when window will be showed, it will be definitely inactive. But calling isActive() returns true in this case. If I switch to my app and switch back to another app, isActive() will be false, as normal. But at first time it is true, which isn't what should normally be. On linux and OS X it works as planned, by the way.
How can I fix it? Or how can I workaround it?
Example code reproducing that issue given below. It's PyQt, but trust me, Qt reproduces this issue too.
import sys
from time import sleep
from PyQt5.QtWidgets import QWidget, QApplication
class BadWidget(QWidget):
def __init__(self):
super(BadWidget, self).__init__()
self.startTimer(500)
def timerEvent(self, e):
print(self.isActiveWindow() and not self.isMinimized())
if __name__ == '__main__':
app = QApplication(sys.argv)
bad_widget = BadWidget()
sleep(1)
bad_widget.show()
app.exec_()