可以在小部件中QVBoxLayout包含 a吗?QStackedLayout我正在尝试创建一个如下所示的自定义小部件:
import sys
from PyQt5.QtWidgets import *
from pyqtgraph import PlotWidget, plot
import pyqtgraph as pg
class MyCustomWidget(QWidget):
    def __init__(self):
        super().__init__()
        self.my_combo_box = QComboBox(self)
        self.vlayout = QVBoxLayout(self)
        self.slayout = QStackedLayout(self)
        self.vlayout.addWidget(self.my_combo_box)
        self.graphWidget = {}
        self.widget = QWidget()
    def add_new_graphics(self, name, x, y):
        self.my_combo_box.addItem(name)
        self.graphWidget[name] = pg.PlotWidget()
        self.graphWidget[name].plot(x, y)
        self.slayout.addWidget(self.graphWidget[name])
        self.vlayout.addWidget(self.slayout)
        self.widget.setLayout(self.vlayout)
app = QApplication([])
a = MyCustomWidget()
x1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y1 = [30, 32, 34, 32, 33, 31, 29, 32, 35, 45]
a.add_new_graphics('data1', x1, y1)
x2 = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
y2 = [0, 2, 4, 2, 3, 1, 9, 2, 5, 5]
a.add_new_graphics('data2', x2, y2)
a.show()
sys.exit(app.exec_())
我收到以下错误:
TypeError: addWidget(self, QWidget, stretch: int = 0, alignment: Union[Qt.Alignment, Qt.AlignmentFlag] = Qt.Alignment()): argument 1 has unexpected type 'QStackedLayout'
sys:1: RuntimeWarning: Visible window deleted. To prevent this, store a reference to the window object.
