Vote count:
0
I am trying to launch a a child window from a window that should always be parent.
I am not getting any error and everything seems fine to me, is it something that I am missing?
import sys
from PyQt4 import QtCore, QtGui
print __file__
class ParentWindow(QtGui.QMainWindow):
"""docstring for ParentWindow"""
def __init__(self, parent=None):
super(ParentWindow, self).__init__(parent)
self.setWindowTitle("Parent Window")
self.setGeometry(300, 300, 250, 150)
self._setupUi()
self._connections()
def _setupUi(self):
self.btn = QtGui.QPushButton("Launch child window in child thread")
self.setCentralWidget(self.btn)
def _connections(self):
self.btn.clicked.connect(self.callChild)
@QtCore.pyqtSlot()
def callChild(self):
childObj = ChildWindow()
childObj.setParent(self)
class ChildWindow(QtGui.QWidget):
def __init__(self, parent=None):
super(ChildWindow, self).__init__(parent)
self.setWindowTitle("Child Window")
print "working"
self.byeBtn = QtGui.QPushButton("Bye", self)
self.childLayout = QtGui.QVBoxLayout()
self.childLayout.addWidget(self.byeBtn)
self.setLayout(self.childLayout)
self.byeBtn.clicked.connect(self.close)
self.show()
def setWindowFlags(self, flags):
print "flags value in setWindowFlags"
print flags
super(ChildWindow, self).setWindowFlags(flags)
def main():
app = QtGui.QApplication(sys.argv)
app.setApplicationName('Parent')
pWinObj = ParentWindow()
pWinObj.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
If I pass self the the childObj
then the child window widget goes inside ParentWindow
.
asked 33 secs ago
Aucun commentaire:
Enregistrer un commentaire