Spawning one window from another window on button click in qt4

后端 未结 2 336
时光取名叫无心
时光取名叫无心 2021-01-27 16:11

I\'ve created two windows using qt4 designer, and would like to link them together. I put them both in a folder and created a file outside the directory, which I\'m importing th

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-27 17:09

    Your question don't show much context but it seems you are new at PyQt and PyUIC tools.

    That you post aren't (or not should be) the real windows of your app. Those class are generated for pyuic or pyuic4.

    You must have something like:

    class RealWindow(QMainWindow):
        def __init__(parent=None):
            super(RealWindow, self).__init__(parent) # Call QMainWindow constructor.
            self.__ui = UI_MainWindow()              # Here is when you should use that class.
            self.__ui.setupUI(self)                  # And apply the properties to yout actual window
    
        def on_some_button_clicked(*args, **args)   # And here is where you do whatever you want to do when you press a button.
    

    On the other hand, I'm not sure is a good idea having two main windows in the same app. I don't know even if Qt allow that at all.

    I recommend you build one of your windows as a QDialog. Or build a single window with a set of controls you can hide or show at will.

    I also recommend you: a pyqt tutorial

提交回复
热议问题