def addButtons(self, frm, btns): layout = frm.findChild((QHBoxLayout, QWidget), 'Layout_Button') layout.setSpacing(2) if not (layout is None): for m in btns: btn = QPushButton(m['fMenuText']) btn.NMID = m['fNMID'] btn.setObjectName(m['fObjectName']) self.addOneButtonIcon(btn, m['fIcon']) btn.setEnabled(m['fHasRight']) layout.addWidget(btn) QMetaObject.connectSlotsByName(frm)
def addButtons(self, frm: QWidget, btns, styleName='Layout_Button'): """给窗体中Layout_Button的布局添加按钮""" layout = frm.findChild((QHBoxLayout, QWidget), styleName) if not (layout is None): layout.setSpacing(2) for m in btns: btn = QPushButton(m['fMenuText']) btn.NMID = m['fNMID'] btn.setObjectName(m['fObjectName']) self.addOneButtonIcon(btn, m['fIcon']) btn.setEnabled(m['fHasRight']) layout.addWidget(btn) else: errStr = "窗体【{}】中没有找到名为'【Layout_Button】'的布局".format( frm.objectName()) errStr = errStr + ",无法添加按钮。" logging.getLogger().warning(errStr) # 设置按名称执行槽函数 QMetaObject.connectSlotsByName(frm)