简体   繁体   中英

How to create Multiple / cascading windows PyQt4?

I want to create 2 windows the upper one needs to be a new project window and the lower one is the project GUI, I have created my lower window completely now I am planning to create a the upper window. How do I create my Upper(New project window)? Can I do it by including a function in my class and calling my function from my run()? or should I create a new class? I am completely confused help me!

My Lower Window(Main Project Code) Code:

class Softw(QtGui.QMainWindow, Doftw.Ui_MainWindow):
    def __init__(self, parent=None):
        super(Softw, self).__init__(parent)
        self.setGeometry(50, 50, 700, 565)
        self.setWindowTitle("Softy Softw")

-------------------------


--------(some Functions in Code)

And then finally my run() function which creates and calls the class

def run():
        app=QtGui.QApplication(sys.argv)
        GUI = Softw()
        GUI.show()
        sys.exit(app.exec_())

run()

If I do a new function in my class the window shows the upper window first then disappears and then shows the lower window:

def newProject(self):
    window = QtGui.QWidget()
    window.setGeometry(700,330,500,300)
    window.setWindowTitle("New Project")
    window.show()

I think the mistake is when to call the function when do I add my function call in this senario? In init method? or Somewhere else?

Thanks!

You can create QWidget using Qt Designer to every window that you want and then you can add them as a class to your file:

For example consider, you have created the .ui file for one window you want to create then convert it to .py using pyuic4 and then create your class like:

from Ui_created import the UI_class

class NewProject(QtGui.QMainWindow, Ui_class):

    def __init__(self, parent = None):
        super(NewProject, self).__init__(parent)
        self.setupUi(self)

Now you can connect this to some button in the main class

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM