在PyQt5中更改布局时如何刷新窗口

时间:2018-09-05 19:18:19

标签: python raspberry-pi pyqt5

因此,我试图使用PyQt5为树莓派创建GUI。该GUI应该在插入设备时读取,并显示连接的列表。到目前为止,我为插入的每个设备都有一个分组框,其中包含png和标签。添加设备后,我希望能够显示另一个显示设备名称的分组框。 即使我知道该设备已添加到连接的设备列表中,也无法刷新显示新设备的GUI。如何刷新显示新布局的窗口。这是我到目前为止的代码

    import sys
    import Download_Logs
    import threading
    import time
    from PyQt5.QtCore import Qt
    from PyQt5 import QtCore
    from PyQt5.QtWidgets import (QApplication, QCheckBox, QGridLayout,                    QGroupBox,
    QMenu, QPushButton, QRadioButton, QVBoxLayout, QWidget, QLabel)
    from PyQt5.QtGui import QIcon, QPixmap



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

            self.initUI()


       def initUI(self):
            print("RUNRURNURNRUN")
            vbox = QVBoxLayout()
            vbox.addStretch(1)
            title = QLabel("Connected Devices")




            vbox.addWidget(title)
            vbox.addLayout(self.showConnectedDevices())


            self.setLayout(vbox)
            self.setWindowTitle("HRAPS Devices")
            self.resize(100, 200)
            self.show()


       def createDeviceGroup(self, name):
            groupBox = QGroupBox()

            name = QLabel(name)
            picture = QLabel()
            pixmap =         QPixmap('/home/pi/GUI/oban.png').scaled(200,200,Qt.KeepAspectRatio,         Qt.FastTransformation)
            picture.setPixmap(pixmap)

            vbox = QVBoxLayout()
            vbox.addWidget(name)
            vbox.addWidget(picture)
            vbox.addStretch(1)
            groupBox.setLayout(vbox)
            return groupBox


        def showConnectedDevices(self):
            connectedDevices = Download_Logs.Get_Connected_Drive_List()
            print("Connected Devices: {}" .format(connectedDevices))

            grid = QGridLayout()
            i = 0;
            j = 0;

            for x in connectedDevices:
                grid.addWidget(self.createDeviceGroup(x), i, j)
                j = j + 1
                if j == 5:
                    i = i + 1
                    j = 0


            self.update()
            return grid


    def maiin():

        print('RUN')
        app = QApplication(sys.argv)
        clock = Window()
        app.exec_()



    if __name__ == '__main__':

        maiin()

0 个答案:

没有答案