[PyQt] modeless dialog - repeated windows

Baz Walter bazwal at ftml.net
Mon Jul 25 13:36:13 BST 2011


On 25/07/11 12:20, Susana Sanchez Exposito wrote:
> I would like if the user  selects the option to open the modeless dialog and
> this dialog is opened yet, this dialog would be focused instead of opening
> another window of the same modeless dialog.

import sys
from PyQt4 import QtGui, QtCore

class Window(QtGui.QPushButton):
     def __init__(self):
         QtGui.QPushButton.__init__(self, 'Open')
         self.dialog = QtGui.QMessageBox(self)
         self.dialog.setWindowModality(QtCore.Qt.NonModal)
         self.clicked.connect(self.showDialog)

     def showDialog(self):
         self.dialog.show()
         self.dialog.activateWindow()

if __name__ == '__main__':

     app = QtGui.QApplication(sys.argv)
     win = Window()
     win.move(600, 400)
     win.dialog.move(600, 500)
     win.show()
     sys.exit(app.exec_())



More information about the PyQt mailing list