Calling activateWindow on QDialog sends window to background
- by Stan
I am debugging certain application written with C++/Qt4. On Linux it has problems that with certain window managers (gnome-wm/metacity), the main window (based on QDialog) is created in the background (it's not raised). I managed to re-create the scenario using PyQt4 and following code:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
class PinDialog(QDialog):
def showEvent(self, event):
QDialog.showEvent(self, event)
self.raise_()
self.activateWindow()
if __name__ == "__main__":
app = QApplication(sys.argv)
widget = PinDialog()
app.setActiveWindow(widget)
widget.exec_()
sys.exit(0)
If I remove
self.activateWindow()
the application works as expected. This seems wrong, since documentation for activateWindow
does not specify any conditions under which something like this could happen.
My question is:
Is there any reason to have activateWindow in showEvent in the first place? If there is some reason, what would be good workaround for focusing issues?