Reputation: 75
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4 import uic
MainWindow = uic.loadUiType("simulator_ver_0.1.ui")[0]
AddFuseWindow = uic.loadUiType("simulator_add_fuse_ver_0.1.ui")[0]
AddLoadWindow = uic.loadUiType("simulator_add_load_ver_0.1.ui")[0]
class MyWindow2(QWidget, AddFuseWindow):
def _init_():
super()._init_(self)
self.setupUi(self)
class MyWindow3(QWidget , AddLoadWindow):
def _init_():
super()._init_(self)
self.setupUi(self)
class MyWindow(QMainWindow, MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.connect(self.actionFuse, SIGNAL("triggered()"), self.add_fuse)
self.connect(self.actionLoad, SIGNAL("triggered()"), self.add_load)
def add_fuse(self):
self.w2 = MyWindow2(self)
self.w2.show()
def add_load(self):
self.w3=MyWindow3()
self.w3.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
myWindow = MyWindow()
myWindow.show()
app.exec_()
here is my python code. I loaded three ui files from qt designer. I already created MyWindow class, which is MainWindow. I want to pop up MyWindow2 or MyWindow3, When I click the toolbar. It was successful to pop up new window , but it was not what I created. It was just empty window. It seems like python didn't load AddFuseWindow and AddLoadWindow. enter image description here
Upvotes: 1
Views: 4494
Reputation: 1113
You can define the new pop up window in a funtion and connect it to the toolbar item.
self.toolbaritem.triggered.connect(self.doSomething)
def doSomething(self):
window = OtherWindow()
window.show()
self.close()
class OtherWindow():
def dothis(self):
window = SampleWin()
window.show()
self.close()
you can also use QStackedWidget to do the same thing.
Upvotes: 1