Hi,
I'm trying to create a modal frameless window, because I don't want the user the
possibility to move the window or accidentally close it. However, there seems to
be an issue with my understanding of QDialogs.
I have attached two snippets that illustrate my problem. The first example
('works-as-expected.py') shows the dialog as I intend to have it. The second
snippet ('does-not-work-as-expected.py') fails to do what I want: it doesn't
show the dialog.
Some things I have noticed in debugging this issue:
1) If I comment out line 12:
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
everything works fine!
2) From my understanding of the documentation of QDialog, setting the parent of
a top-level window should result in the dialog being centered on top of its
parent. However, setting the parent has no effect in this case.
3) In the application I work on, I can see a little bit of the dialog peeking
through the parent's layout: it seems the dialog has become a widget embedded
in the parent somehow. I cannot reproduce this behavior in this simplified
example.
4) I have the same issue with PyQt4, so I don't think it is a bug in PySide.
Any ideas? I'm using Python 2.7 + PySide 1.1.0.
Best regards,
Ludo Visser
from PySide import QtCore, QtGui
class ModalDialog(QtGui.QDialog):
def __init__(self, *args, **kwargs):
QtGui.QDialog.__init__(self, *args, **kwargs)
btnClose = QtGui.QPushButton('Close me!')
btnClose.clicked.connect(self.hide)
self.setLayout(QtGui.QVBoxLayout())
self.layout().addWidget(btnClose)
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
self.setModal(True)
self.show()
if __name__ == '__main__':
app = QtGui.QApplication([])
md = ModalDialog()
app.exec_()
from PySide import QtCore, QtGui
class ModalDialog(QtGui.QDialog):
def __init__(self, *args, **kwargs):
QtGui.QDialog.__init__(self, *args, **kwargs)
btnClose = QtGui.QPushButton('Close me!')
btnClose.clicked.connect(self.hide)
self.setLayout(QtGui.QVBoxLayout())
self.layout().addWidget(btnClose)
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
self.setModal(True)
self.show()
class MainDialog(QtGui.QDialog):
def __init__(self, *args, **kwargs):
QtGui.QDialog.__init__(self, *args, **kwargs)
btnOpen = QtGui.QPushButton('Open modal dialog')
btnOpen.clicked.connect(self.showModalDialog)
self.setLayout(QtGui.QVBoxLayout())
self.layout().addWidget(btnOpen)
self.show()
def showModalDialog(self):
md = ModalDialog(parent=self)
if __name__ == '__main__':
app = QtGui.QApplication([])
m = MainDialog()
app.exec_()
--
Ludo C. Visser, M.Sc.
Science Applied
phone: +31 6 1066 3076
e-mail: [email protected]
web: www.science-applied.nl
_______________________________________________
PySide mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/pyside