[PyQt] Dialog Window's Position Offset

Brent Villalobos Brent.Villalobos at pdi.dreamworks.com
Wed Sep 23 02:05:51 BST 2009


I'm confused about the position of dialogs that do not have parents.  I 
wrote a small PyQt application that is a push button that launches a 
non-modal, non-parented QDialog.  When you show the dialog and then 
close it without explicitly moving it, then it reports the wrong 
position.  However, the position gets reported just fine on close if I 
move the dialog box.

If you run my test code (shown below), you get this output when you push 
the "Show Dialog" button and then close the dialog right away (your 
actual values may differ):
Dialog Moved:  PyQt4.QtCore.QPoint(2075, 336)
Dialog Moved:  PyQt4.QtCore.QPoint(1600, 336)
Dialog Closed:  PyQt4.QtCore.QPoint(1595, 312)

The position on close is always offset by (-5, -24).  Why?  Will those 
offset values always be the same or is there a way I can query for those 
offset values?

#### Code ####
import sys
from PyQt4 import QtGui, QtCore

myDialog = None

class MyDialog(QtGui.QDialog):
    def __init__(self, parent=None):
        super(MyDialog, self).__init__(parent)
        self.setModal(False)

    def moveEvent(self, e):
        print "Dialog Moved: ", self.pos()

    def closeEvent(self, e):
        print "Dialog Closed: ", self.pos()

def showDialog():
    global myDialog
    myDialog = MyDialog()
    myDialog.show()

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    button = QtGui.QPushButton("Show Dialog")
    QtCore.QObject.connect(button, QtCore.SIGNAL("clicked()"), showDialog)
    button.show()
    sys.exit(app.exec_())




More information about the PyQt mailing list