Pyqt以不同的布局添加相同的小部件对象

问题描述 投票:0回答:1

我现在想使用Pyqt设计这样的逻辑集,在两个布局中添加两个不同的窗口小部件,这两个不同的窗口小部件使用相同的窗口小部件,因为我想在不同的布局中共享同一窗口小部件的数据,但是不幸的是我设计失败,在这种情况下,我无法在显示器上显示两个PYQT,有人可以帮我吗


from PyQt4.QtGui import *
from PyQt4.QtCore import *


class Series(QWidget):
    def __init__(self):
        super(Series, self).__init__()
        self.lb = QLabel('PYQT')


class SeriesHBox1(QWidget):
    def __init__(self, series):
        super(SeriesHBox1, self).__init__()
        self.vbox = QVBoxLayout()
        self.setLayout(self.vbox)
        self.vbox.addWidget(series.lb)


class SeriesHBox2(QWidget):
    def __init__(self, series):
        super(SeriesHBox2, self).__init__()
        self.hbox = QHBoxLayout()
        self.setLayout(self.hbox)
        self.hbox.addWidget(series.lb)


class Example(QWidget):
    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):
        self.setGeometry(300, 300, 500, 300)
        box = QHBoxLayout()
        self.setLayout(box)

        box1 = QHBoxLayout()
        box2 = QHBoxLayout()
        box.addLayout(box1)
        box.addLayout(box2)

        series = Series()
        box1.addWidget(SeriesHBox1(series))
        box2.addWidget(SeriesHBox2(series))
        # box2.addWidget(SeriesHBox2(Series()))

        self.show()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())
python qt pyqt
1个回答
0
投票

[抱歉,我有PyQt5。创建Series类的两个实例

© www.soinside.com 2019 - 2024. All rights reserved.