gpt4 book ai didi

python - 打开的 QtiPlot 窗口列表

转载 作者:太空宇宙 更新时间:2023-11-03 19:25:31 27 4
gpt4 key购买 nike

我正在使用 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();

最佳答案

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

希望这会有所帮助!

关于python - 打开的 QtiPlot 窗口列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8294173/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com