class Ui_Form(QWidget): def __init__(self, *args, **kwargs): QWidget.__init__(self, *args, **kwargs) self.setupUi(self) self.client = Client('localhost') def setupUi(self, Form): Form.setObjectName("Form") Form.resize(8, 600) self.horizontalLayout = QHBoxLayout(Form) self.horizontalLayout.setObjectName("horizontalLayout") self.horizontalLayout.setGeometry(QRect(0, 0, 600, 600)) self.horizontalLayout.setSizeConstraint(QLayout.SetFixedSize) self.gridLayout = QGridLayout() # self.gridLayout.setSizeConstraint(QLayout.SetMaximumSize) self.gridLayout.setObjectName("gridLayout") self.horizontalLayout.addLayout(self.gridLayout) self.row = 0; self.col = 0; self.width = 3; self.entries = [] self.retranslateUi(Form) QMetaObject.connectSlotsByName(Form) def retranslateUi(self, Form): _translate = QCoreApplication.translate Form.setWindowTitle(_translate("Form", "Form")) def addImageLabel(self, pic): print (pic) pixmap = QPixmap(pic).scaled(200, 200, Qt.KeepAspectRatio) label = QLabel(self) label.setPixmap(pixmap) self.entries.append(label) self.gridLayout.addWidget(label, *(self.row, self.col)) self.col += 1 if self.col % self.width == 0: self.col = 0 self.row += 1 def removeImageLabel(self, position): item = position[0] * self.width + position[1] label = self.gridLayout.takeAt(item) widget = label.widget(); widget.deleteLater(); def run(self): self.client.getAllPhoto() jpgList = glob.glob1("temp", "*.jpg") for each in jpgList: self.addImageLabel("temp/" + each)
class Ui_Form(QWidget): def __init__(self, *args, **kwargs): QWidget.__init__(self, *args, **kwargs) self.setupUi(self) self.client = Client('localhost') def setupUi(self, Form): Form.setObjectName("Form") Form.resize(1000, 688) contents = QWidget(self) contents.setGeometry(QtCore.QRect(800, 40, 100, 30)) self.getPhotoBtn = QtWidgets.QPushButton(contents) self.getPhotoBtn.setObjectName("getPhotoBtn") self.getPhotoBtn.clicked.connect(self.getPhotoBtnEvent) contents = QWidget(self) contents.setGeometry(QtCore.QRect(800, 80, 100, 30)) self.synchBtn = QtWidgets.QPushButton(contents) self.synchBtn.setObjectName("synchBtn") self.synchBtn.clicked.connect(self.synchBtnEvent) self.horizontalLayoutContents = QtWidgets.QWidget(self) self.horizontalLayoutContents.setGeometry(QRect(40, 40, 700, 600)) self.horizontalLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutContents) self.scrollAreaWidgetContents = QtWidgets.QWidget() self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 600, 600)) self.gridLayout = QtWidgets.QGridLayout() self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.scrollAreaWidgetContents) self.horizontalLayout_2.addLayout(self.gridLayout) self.scrollArea = QtWidgets.QScrollArea(self) self.scrollArea.setWidgetResizable(True) self.scrollArea.setWidget(self.scrollAreaWidgetContents) self.horizontalLayout.addWidget(self.scrollArea) self.row = 0; self.col = 0; self.width = 3; self.entries = [] self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form) def getPhotoBtnEvent(self): self.client.getAllPhoto() jpgList = glob.glob1("temp", "*.jpg") for each in jpgList: self.addImageLabel(each) def synchBtnEvent(self): self.client.synchrinize() def retranslateUi(self, Form): _translate = QtCore.QCoreApplication.translate Form.setWindowTitle(_translate("Form", "Form")) self.getPhotoBtn.setText(_translate("Form", "getphoto")) self.synchBtn.setText(_translate("Form", "synchronize")) def addImageLabel(self, pic): pixmap = QPixmap('temp/' + pic).scaled(200, 200, Qt.KeepAspectRatio) label = MyQLabel(self) label.setName(pic) label.setPixmap(pixmap) self.entries.append(label) self.gridLayout.addWidget(label, *(self.row, self.col)) self.col += 1 if self.col % self.width == 0: self.col = 0 self.row += 1 def removeImageLabel(self, position): item = position[0] * self.width + position[1] label = self.gridLayout.takeAt(item) widget = label.widget(); widget.deleteLater();