views:

105

answers:

1

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?

+1  A: 

I. too, have seen this behaviour.

According to the documentation:

On X11, the result depends on the Window Manager

It appears that Gnome is taking the same stance as Microsoft Windows in not allowing an application to interrupt what the user is currently doing in another application (in this case Terminal).

Johnsyweb
Well I would understand that if I it would just ignore call to activateWindow because my window is not on top, but it effectively does exact opposite (see my note about removing the call). I am starting to think this is a bug in either gnome-wm or Qt4
Stan