2011-11-28 82 views
1

我正在为使用Python的QtiPlot编写一个插件。在这个插件的GUI中,我想显示一个下拉列表,其中包含一个窗口(绘图,表格,注释等)的所有打开窗口的列表。例如,点击一个保存表格的下拉菜单项,我想加载这个表格来处理它。有没有建议如何解决这个问题?打开QtiPlot窗口列表

我发现的唯一东西是QtiPlot-Manual的第7.2.6段。

编辑: 我现在领先一步。我现在可以获取子窗口名称的列表。但是现在我使用下面的代码在gtiplot脚本窗口中显示gui时出现问题。

# Import system libraries. 
import os,sys 

# Import Qt modules. 
from PyQt4 import QtCore,QtGui 

class Widget(QtGui.QMainWindow): 

    def __init__(self): 
     super(Widget, self).__init__(); 
     self.initUI(); 

    def initUI(self): 
     # Set the window label. 
     self.lbl = QtGui.QLabel("", self); 

     # Fetch the QMdiArea object ... 
     ws = workspace(); 

     # ... and fetch all subwindows. 
     subs = ws.subWindowList(); 

     # Initialize the combobox ... 
     combo = QtGui.QComboBox(self); 

     # ... and add the items. 
     for sub in subs: 
      combo.addItem(sub.objectName()); 

     combo.move(50, 50); 
     self.lbl.move(50, 150); 

     combo.activated[str].connect(self.onActivated);  

     self.setGeometry(300, 300, 300, 200); 
     self.setWindowTitle('Subwindow DropDown'); 
     self.show(); 

    def onActivated(self, text): 
     self.lbl.setText(text); 
     self.lbl.adjustSize(); 

def main(): 
    app = QtGui.QApplication(sys.argv); 
    widget = Widget(); 
    sys.exit(app.exec_()); 

if __name__ == '__main__': 
    main(); 

回答

1
import os,sys 
from PyQt4 import QtCore,QtGui 

class Widget(QtGui.QMainWindow): 

    def __init__(self): 
     super(Widget, self).__init__(); 
     self.initUI(); 

    def initUI(self): 
     # Set the window label. 
     self.lbl = QtGui.QLabel("", self); 

     # Fetch the QMdiArea object ... 
     ws = workspace(); 

     # ... and fetch all subwindows. 
     subs = ws.subWindowList(); 

     # Initialize the combobox ... 
     combo = QtGui.QComboBox(self); 

     # ... and add the items. 
     for sub in subs: 
      combo.addItem(sub.objectName()); 

     combo.move(50, 50); 
     self.lbl.move(50, 150); 

     combo.activated[str].connect(self.onActivated);  

     self.setGeometry(300, 300, 300, 200); 
     self.setWindowTitle('Subwindow DropDown'); 
     self.show(); 

    def onActivated(self, text): 
     self.lbl.setText(text); 
     self.lbl.adjustSize(); 

widget = Widget(); 

我希望这有助于!

+0

请翻译成英文 –