def _init_ui(self): Payment.add_all_payment(self.payment) completer = QCompleter(self._get_all_supplier()) completer.setCaseSensitivity(Qt.CaseInsensitive) completer.setFilterMode(Qt.MatchContains) self.supplier.setCompleter(completer) pyqt_utils.set_validator(self.price, 'float') pyqt_utils.set_validator(self.unpaid, 'float')
def _init_first_line(self): self.line_number = 1 self.buy_date_1.setDateTime(QDateTime.fromString(time_utils.get_now(), 'yyyy-MM-dd hh:mm:ss')) self._add_all_service_item(self.service_1) Payment.add_all_payment(self.payment_1) for title in self.line_title: name = title + '_' + '1' editor = getattr(self, name) self._set_completer(editor, title) pyqt_utils.set_validator(self.price_1, 'float') pyqt_utils.set_validator(self.paid_1, 'float') self.paid_1.setText('0.0') self.price_1.setText('0.0') self.total_1.setText('0.0') self.unpaid_1.setText('0.0')
def _add_new_line(self): if self.buy_info_container.count() >= 11: QMessageBox.information(self.submit, "提示", '添加的行数过多,请提交后再做新增!') return self.line_number += 1 line_number = str(self.line_number) buy_info_name = 'buy_info' + '_' + line_number setattr(self, buy_info_name, QtWidgets.QHBoxLayout()) buy_info = getattr(self, buy_info_name) buy_info.setObjectName(buy_info_name) for index, title in enumerate(self.line_title): editor = self.create_instance('PyQt5.QtWidgets.' + self.edit_type[index]) attr_name = title + '_' + line_number editor.setObjectName(attr_name) first_attr_name = title + '_' + '1' first_attr = getattr(self, first_attr_name) editor.setMinimumSize(getattr(first_attr, 'minimumSize')()) editor.setMaximumSize(getattr(first_attr, 'maximumSize')()) editor.setFont(getattr(first_attr, 'font')()) if hasattr(first_attr, 'setClearButtonEnabled') and first_attr.isClearButtonEnabled(): editor.setClearButtonEnabled(True) if title == 'buy_date': editor.setDisplayFormat("yyyy-MM-dd") editor.setDateTime(QDateTime.fromString(time_utils.get_now(), 'yyyy-MM-dd hh:mm:ss')) if title == 'remove': editor.setText('删除') editor.clicked.connect(self.do_remove) editor.setObjectName(attr_name) if title == 'seq': editor.setText(line_number) # 只读 if title in ('total', 'unpaid'): editor.setReadOnly(first_attr.isReadOnly()) editor.setEnabled(first_attr.isEnabled()) editor.setText('0.0') if title in ('paid', 'price'): pyqt_utils.set_validator(editor, 'float') editor.textEdited.connect(self._text_edit) editor.setText('0.0') if title == 'number': editor.valueChanged.connect(self._text_edit) if title == 'service': self._add_all_service_item(editor) if title == 'payment': Payment.add_all_payment(editor) self._set_completer(editor, title) setattr(self, attr_name, editor) buy_info.addWidget(editor) self.buy_info_container.addLayout(buy_info)