qt4 - How to call one mainwindow to another mainwindow in Qt (or PyQt) -
in project have created 2 mainwindow want call mainwindow2 mainwindow1 (which in running). in mainwindow1 used app.exec_() (pyqt) , show maindow2 using maindow2.show() in click event of button not show anything
calling mainwindow2.show() should work you. give more complete example of code? there may wrong somewhere else.
edit: code updated show example of how hide , show windows when opening , closing other windows.
from pyqt4.qtgui import qapplication, qmainwindow, qpushbutton, \ qlabel, qvboxlayout, qwidget pyqt4.qtcore import pyqtsignal class mainwindow1(qmainwindow): def __init__(self, parent=none): qmainwindow.__init__(self, parent) button = qpushbutton('test') button.clicked.connect(self.newwindow) label = qlabel('mainwindow1') centralwidget = qwidget() vbox = qvboxlayout(centralwidget) vbox.addwidget(label) vbox.addwidget(button) self.setcentralwidget(centralwidget) def newwindow(self): self.mainwindow2 = mainwindow2(self) self.mainwindow2.closed.connect(self.show) self.mainwindow2.show() self.hide() class mainwindow2(qmainwindow): # qmainwindow doesn't have closed signal, we'll make one. closed = pyqtsignal() def __init__(self, parent=none): qmainwindow.__init__(self, parent) self.parent = parent label = qlabel('mainwindow2', self) def closeevent(self, event): self.closed.emit() event.accept() def startmain(): app = qapplication(sys.argv) mainwindow1 = mainwindow1() mainwindow1.show() sys.exit(app.exec_()) if __name__ == "__main__": import sys startmain()
Comments
Post a Comment