Calling activateWindow on QDialog sends window to background

Posted by Stan on Stack Overflow See other posts from Stack Overflow or by Stan
Published on 2010-05-07T12:29:08Z Indexed on 2010/05/07 12:38 UTC
Read the original article Hit count: 385

Filed under:
|
|
|
|

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?

© Stack Overflow or respective owner

Related posts about qt

Related posts about c++