• <tfoot id='vTCU2'></tfoot>
    <i id='vTCU2'><tr id='vTCU2'><dt id='vTCU2'><q id='vTCU2'><span id='vTCU2'><b id='vTCU2'><form id='vTCU2'><ins id='vTCU2'></ins><ul id='vTCU2'></ul><sub id='vTCU2'></sub></form><legend id='vTCU2'></legend><bdo id='vTCU2'><pre id='vTCU2'><center id='vTCU2'></center></pre></bdo></b><th id='vTCU2'></th></span></q></dt></tr></i><div id='vTCU2'><tfoot id='vTCU2'></tfoot><dl id='vTCU2'><fieldset id='vTCU2'></fieldset></dl></div>

      1. <legend id='vTCU2'><style id='vTCU2'><dir id='vTCU2'><q id='vTCU2'></q></dir></style></legend>

        • <bdo id='vTCU2'></bdo><ul id='vTCU2'></ul>

        <small id='vTCU2'></small><noframes id='vTCU2'>

      2. PyQt:如何从 Qt Designer 加载多个 .ui 文件

        时间:2023-08-05
        <i id='UaTjS'><tr id='UaTjS'><dt id='UaTjS'><q id='UaTjS'><span id='UaTjS'><b id='UaTjS'><form id='UaTjS'><ins id='UaTjS'></ins><ul id='UaTjS'></ul><sub id='UaTjS'></sub></form><legend id='UaTjS'></legend><bdo id='UaTjS'><pre id='UaTjS'><center id='UaTjS'></center></pre></bdo></b><th id='UaTjS'></th></span></q></dt></tr></i><div id='UaTjS'><tfoot id='UaTjS'></tfoot><dl id='UaTjS'><fieldset id='UaTjS'></fieldset></dl></div>

        <small id='UaTjS'></small><noframes id='UaTjS'>

            • <bdo id='UaTjS'></bdo><ul id='UaTjS'></ul>
                <tbody id='UaTjS'></tbody>

              1. <legend id='UaTjS'><style id='UaTjS'><dir id='UaTjS'><q id='UaTjS'></q></dir></style></legend>
                • <tfoot id='UaTjS'></tfoot>
                  本文介绍了PyQt:如何从 Qt Designer 加载多个 .ui 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想添加启动窗口,当我单击按钮时,它将打开另一个窗口并关闭当前窗口.对于每个窗口,它都有从 Qt Designer 以 .ui 形式创建的独立 UI.

                  I want to add startup window that when I click button, it will open another window and close current window. For each window, it has seperated UI which created from Qt Designer in .ui form.

                  我通过 uic.loadUiType() 加载两个 .ui 文件.第一个窗口(第一个 UI)通常可以显示其 UI,但是当我单击按钮转到另一个窗口时,另一个 UI(第二个 UI)不起作用.它喜欢打开空白窗口.

                  I load both .ui file via uic.loadUiType(). The first window(first UI) can normally show its UI but when I click button to go to another window, another UI (second UI) doesn't work. It likes open blank window.

                  另一个问题是,如果我加载第一个 UI,然后更改为第二个 UI(删除该类并更改为另一个类,同时删除 uic.loadUiType()),第二个 UI 仍然不起作用(显示空白窗口)

                  Another problem is if I load first UI and then change to second UI (delete that Class and change to another Class, also delete uic.loadUiType()), the second UI still doesn't work (show blank window)

                  请帮助...我在创建此问题之前进行了研究,但找不到答案.

                  Please help... I research before create this question but can't find the answer.

                  这是我的代码.我该如何解决?

                  Here's my code. How can I fix it?

                  import sys
                  from PyQt5.QtWidgets import QApplication, QWidget
                  from PyQt5.QtGui import QIcon
                  from PyQt5 import uic
                  
                  #load both ui file
                  uifile_1 = 'UI/openPage.ui'
                  form_1, base_1 = uic.loadUiType(uifile_1)
                  
                  uifile_2 = 'UI/mainPage.ui'
                  form_2, base_2 = uic.loadUiType(uifile_2)
                  
                  class Example(base_1, form_1):
                      def __init__(self):
                          super(base_1,self).__init__()
                          self.setupUi(self)
                          self.startButton.clicked.connect(self.change)
                  
                      def change(self):
                          self.main = MainPage()
                          self.main.show()
                  
                  class MainPage(base_2, form_2):
                      def __int__(self):
                          super(base_2, self).__init__()
                          self.setupUi(self)
                  
                  if __name__ == '__main__':
                      app = QApplication(sys.argv)
                      ex = Example()
                      ex.show()
                      sys.exit(app.exec_())
                  

                  推荐答案

                  首先出现错误,必须将__int__改为__init__.要关闭窗口,请调用 close() 方法.

                  First you have an error, you must change __int__ to __init__. To close the window call the close() method.

                  import sys
                  from PyQt5.QtWidgets import QApplication, QWidget
                  from PyQt5.QtGui import QIcon
                  from PyQt5 import uic
                  
                  #load both ui file
                  uifile_1 = 'UI/openPage.ui'
                  form_1, base_1 = uic.loadUiType(uifile_1)
                  
                  uifile_2 = 'UI/mainPage.ui'
                  form_2, base_2 = uic.loadUiType(uifile_2)
                  
                  class Example(base_1, form_1):
                      def __init__(self):
                          super(base_1,self).__init__()
                          self.setupUi(self)
                          self.startButton.clicked.connect(self.change)
                  
                      def change(self):
                          self.main = MainPage()
                          self.main.show()
                          self.close()
                  
                  class MainPage(base_2, form_2):
                      def __init__(self):
                          super(base_2, self).__init__()
                          self.setupUi(self)
                  
                  if __name__ == '__main__':
                      app = QApplication(sys.argv)
                      ex = Example()
                      ex.show()
                      sys.exit(app.exec_())
                  

                  这篇关于PyQt:如何从 Qt Designer 加载多个 .ui 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使用pyqtgraph TimeAxisItem使X轴时间动态刷新 下一篇:如何在 python 和 qml 中自动插入/编辑 QAbstractList

                  相关文章

                  最新文章

                • <legend id='NjGUQ'><style id='NjGUQ'><dir id='NjGUQ'><q id='NjGUQ'></q></dir></style></legend>
                • <small id='NjGUQ'></small><noframes id='NjGUQ'>

                      <bdo id='NjGUQ'></bdo><ul id='NjGUQ'></ul>
                    1. <tfoot id='NjGUQ'></tfoot>
                      <i id='NjGUQ'><tr id='NjGUQ'><dt id='NjGUQ'><q id='NjGUQ'><span id='NjGUQ'><b id='NjGUQ'><form id='NjGUQ'><ins id='NjGUQ'></ins><ul id='NjGUQ'></ul><sub id='NjGUQ'></sub></form><legend id='NjGUQ'></legend><bdo id='NjGUQ'><pre id='NjGUQ'><center id='NjGUQ'></center></pre></bdo></b><th id='NjGUQ'></th></span></q></dt></tr></i><div id='NjGUQ'><tfoot id='NjGUQ'></tfoot><dl id='NjGUQ'><fieldset id='NjGUQ'></fieldset></dl></div>