打开的QtiPlot窗口列表

1 投票
1 回答
577 浏览
提问于 2025-04-17 07:13

我正在用Python为QtiPlot写一个插件。在这个插件的界面里,我想显示一个下拉菜单,里面列出所有打开的窗口,比如图表、表格、笔记等。当我点击下拉菜单中的某个表格项时,我希望能加载这个表格来进行操作。有没有什么建议可以解决这个问题?

我找到的唯一信息是QtiPlot手册的第7.2.6段。

编辑: 我现在进展了一步。我能够获取子窗口名称的列表了。但现在我在用以下代码显示QtiPlot脚本窗口中的界面时遇到了问题。

# 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 个回答

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();

希望这对你有帮助!

撰写回答