PyQt - 打开新窗口,打开后立即关闭

时间:2017-09-14 16:43:15

标签: python pyqt pyqt4 pyqt5 qgis

我试图找出打开后窗户关闭的原因。我查看了为什么这种情况发生在其他人的例子,但我的应用程序设置有点不同(可能是pyqt的新版本比我正在看的那些或因为我从工具栏菜单中启动)。

以下是启动Class1Base类型的第一个窗口并且启动但丢失第二个窗口NewWindow(必须更改匿名名称)的代码的主要部分。

在ToolbarMenuSetup.py中:

class ToolbarMenuSetup(object):
   # only including call to the below for brevity
   def clickOpenClass1(self):
      self.config = self.toolbarConfig()
      retval = Class1(self.class1_dlg, self.config)

在Class1.py中:

class Class1(Class1Base):
   def __init__(self, dlg, config):
      self.dlg = dlg
      self.iface = self.dlg.iface
      self.config = config

      self.dlg.ui.btnOpenWindow.clicked.connect(self.openNewWindow)
      self.run()

在Class1Base.py中:

class NewWindow(Qt.QDialog, UI_NewWindowBase):
   def __init__(self, ToolbarMenuSetup):
      QtGui.QDialog.__init__(self)
      self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
      self.setupUi(self)

class Class1Base():
   def __init__(self, dlg, config):
      self.dlg = dlg
      self.iface = self.dlg.iface
      self.run()

   def openNewWindow(self):
      window = NewWindow(self)
      window.show()

   def run(self):
      self.dlg.show()
      result = self.dlg.exec_()
      if(result):
         performCalculations() 
         # this function not included for brevity

非常感谢任何帮助!

解决方案:
- 将self.window = None添加到run()中 - 在openNewWindow()

中的行前面添加了self.

0 个答案:

没有答案
相关问题