2011-11-28 84 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

請翻譯成英文 –