【问题标题】:List of open QtiPlot windows打开的 QtiPlot 窗口列表
【发布时间】:2011-11-28 10:01:36
【问题描述】:

我正在使用 Python 为 QtiPlot 编写插件。在这个插件的 GUI 中,我想显示一个下拉列表,其中包含一种窗口(绘图、表格、注释等)的所有打开窗口的列表。例如,单击包含表格的下拉列表项时,我想加载此表格以使用它。有什么建议可以解决这个问题吗?

我发现的唯一内容是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();

【问题讨论】:

    标签: python plugins scripting plot pyqt


    【解决方案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();
    

    我希望这会有所帮助!

    【讨论】:

    • 请翻译成英文
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-14
    • 2011-04-25
    • 2022-06-10
    • 1970-01-01
    • 2010-09-20
    相关资源
    最近更新 更多