def newAction(self, name, action, shortcut=None, icon=None): """Make actions quickly""" if icon: Action = QtWidgets.QAction(QtWidgets.QIcon(icon), name, self) else: Action = QtWidgets.QAction(name, self) Action.triggered.connect(action) if shortcut: Action.setShortcut(shortcut) return Action
def updateGridLayout(self, xmlFiles): if xmlFiles: while self.count() > 0: widget = self.itemAt(0).widget() self.removeWidget(widget) widget.deleteLater() for xmlFile in xmlFiles: currentRow = 0 currentColumn = 0 while (self.itemAtPosition(currentRow, currentColumn)): if currentColumn == self.maxColumnCount - 1: currentColumn = 0 currentRow += 1 else: currentColumn += 1 btn = QtWidgets.QPushButton() btn.clicked.connect(self.open_file) try: pixmap = QtWidgets.QPixmap(r'D:\pycharmwjj\test5\Icon.png') buttonIcon = QtWidgets.QIcon(pixmap) btn.setIcon(buttonIcon) btn.setFixedSize(pixmap.rect().size()) btn.setFixedSize(pixmap.rect().size()) except: pass label = QtWidgets.QLabel( os.path.basename(xmlFile).split('.')[0]) vLayout = QtWidgets.QVBoxLayout() widget = QtWidgets.QWidget() widget.setLayout(vLayout) vLayout.addStretch(1) vLayout.addWidget(btn) vLayout.addWidget(label) self.addWidget(widget, currentRow, currentColumn)