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

      1. <small id='YfVsW'></small><noframes id='YfVsW'>

      2. <i id='YfVsW'><tr id='YfVsW'><dt id='YfVsW'><q id='YfVsW'><span id='YfVsW'><b id='YfVsW'><form id='YfVsW'><ins id='YfVsW'></ins><ul id='YfVsW'></ul><sub id='YfVsW'></sub></form><legend id='YfVsW'></legend><bdo id='YfVsW'><pre id='YfVsW'><center id='YfVsW'></center></pre></bdo></b><th id='YfVsW'></th></span></q></dt></tr></i><div id='YfVsW'><tfoot id='YfVsW'></tfoot><dl id='YfVsW'><fieldset id='YfVsW'></fieldset></dl></div>
          <bdo id='YfVsW'></bdo><ul id='YfVsW'></ul>
      3. 在 PyQt 中打开第二个窗口

        Open a second window in PyQt(在 PyQt 中打开第二个窗口)
        <i id='xMV5A'><tr id='xMV5A'><dt id='xMV5A'><q id='xMV5A'><span id='xMV5A'><b id='xMV5A'><form id='xMV5A'><ins id='xMV5A'></ins><ul id='xMV5A'></ul><sub id='xMV5A'></sub></form><legend id='xMV5A'></legend><bdo id='xMV5A'><pre id='xMV5A'><center id='xMV5A'></center></pre></bdo></b><th id='xMV5A'></th></span></q></dt></tr></i><div id='xMV5A'><tfoot id='xMV5A'></tfoot><dl id='xMV5A'><fieldset id='xMV5A'></fieldset></dl></div>

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

                  <tbody id='xMV5A'></tbody>
              • <legend id='xMV5A'><style id='xMV5A'><dir id='xMV5A'><q id='xMV5A'></q></dir></style></legend><tfoot id='xMV5A'></tfoot>

                  <bdo id='xMV5A'></bdo><ul id='xMV5A'></ul>

                • 本文介绍了在 PyQt 中打开第二个窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用 pyqt 在单击 QMainWindow 上的按钮时显示自定义 QDialog 窗口.我不断收到以下错误:

                  I'm trying to use pyqt to show a custom QDialog window when a button on a QMainWindow is clicked. I keep getting the following error:

                  $ python main.py 
                  DEBUG: Launch edit window
                  Traceback (most recent call last):
                    File "/home/james/Dropbox/Database/qt/ui_med.py", line 23, in launchEditWindow
                      dialog = Ui_Dialog(c)
                    File "/home/james/Dropbox/Database/qt/ui_edit.py", line 15, in __init__
                      QtGui.QDialog.__init__(self)
                  TypeError: descriptor '__init__' requires a 'sip.simplewrapper' object but received a 'Ui_Dialog'
                  

                  我已经阅读了几个在线教程,但其中大多数都没有展示如何使用非内置对话窗口.我使用 pyuic4 为主窗口和对话框生成了代码.我认为应该是相关代码如下.我在这里错过了什么?

                  I've gone over several online tutorials, but most of them stop just short of showing how to use a non built-in dialog window. I generated the code for both the main window and the dialog using pyuic4. What I think should be the relevant code is below. What am I missing here?

                  class Ui_Dialog(object):
                      def __init__(self, dbConnection):
                          QtGui.QDialog.__init__(self)
                          global c
                          c = dbConnection
                  
                  class Ui_MainWindow(object):
                      def __init__(self, dbConnection):
                          global c
                          c = dbConnection
                  
                      def launchEditWindow(self):
                          print "DEBUG: Launch edit window"
                          dialog = QtGui.QDialog()
                          dialogui = Ui_Dialog(c)
                          dialogui = setupUi(dialog)
                          dialogui.show()
                  
                  class StartQT4(QtGui.QMainWindow):
                      def __init__(self, parent=None):
                          QtGui.QWidget.__init__(self, parent)
                          conn = sqlite3.connect('meds.sqlite')
                          c = conn.cursor()
                          self.ui = Ui_MainWindow(c)
                          self.ui.setupUi(self)
                  
                  def main():
                      app = QtGui.QApplication(sys.argv)
                      program = StartQT4()
                      program.show()
                      sys.exit(app.exec_())
                  
                  if __name__ == '__main__':
                      main()
                  

                  额外的问题:因为看起来你不能在 pyqt 函数回调中传递参数,所以将一些本来可以作为参数传递的东西(名称不佳的c")设置为全局,这是获取信息的最佳方式那些功能?

                  Bonus question: since it looks like you can't pass arguments in pyqt function callbacks, is setting something which would otherwise be passed as an argument (the poorly named "c") to be global the best way to get information into those functions?

                  推荐答案

                  我过去做过这样的事情,我可以说它有效.假设您的按钮被称为按钮"

                  I've done like this in the past, and i can tell it works. assuming your button is called "Button"

                  class Main(QtGui.QMainWindow):
                      ''' some stuff '''
                      def on_Button_clicked(self, checked=None):
                          if checked==None: return
                          dialog = QDialog()
                          dialog.ui = Ui_MyDialog()
                          dialog.ui.setupUi(dialog)
                          dialog.setAttribute(QtCore.Qt.WA_DeleteOnClose)
                          dialog.exec_()
                  

                  这适用于我的应用程序,我相信它也应该适用于您的应用程序.希望它会有所帮助,应该非常直接地进行一些更改以将其应用于您的案例.祝大家有个美好的一天.

                  This works for my application, and I believe it should work with yours as well. hope it'll help, it should be pretty straight forward to do the few changes needed to apply it to your case. have a good day everybody.

                  这篇关于在 PyQt 中打开第二个窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                  Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                  Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                  Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)
                • <small id='QjPsC'></small><noframes id='QjPsC'>

                  <tfoot id='QjPsC'></tfoot>

                    <bdo id='QjPsC'></bdo><ul id='QjPsC'></ul>

                      <legend id='QjPsC'><style id='QjPsC'><dir id='QjPsC'><q id='QjPsC'></q></dir></style></legend>

                        <tbody id='QjPsC'></tbody>

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