Dialogadd.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # coding:utf8
  2. '''
  3. @Project :Scan
  4. @File :Dialogadd.py
  5. @Author :Leslie
  6. @Date :2023/5/8 11:08
  7. '''
  8. from PyQt5.QtWidgets import QDialogButtonBox, QDateTimeEdit, QDialog, QComboBox, QTableView, QAbstractItemView, \
  9. QHeaderView, QTableWidget, QTableWidgetItem, QMessageBox, QListWidget, QListWidgetItem, QStatusBar, QMenuBar, QMenu, \
  10. QAction, QLineEdit, QStyle, QFormLayout, QVBoxLayout, QWidget, QApplication, QHBoxLayout, QPushButton, QMainWindow, \
  11. QGridLayout, QLabel
  12. from PyQt5.QtGui import QIcon, QPixmap, QStandardItem, QStandardItemModel, QCursor, QFont, QBrush, QColor, QPainter, \
  13. QMouseEvent, QImage, QTransform
  14. from PyQt5.QtCore import QStringListModel, QAbstractListModel, QModelIndex, QSize, Qt, QObject, pyqtSignal, QTimer, \
  15. QEvent, QDateTime, QDate
  16. class Dialogadd(QDialog):
  17. # 自定义消息
  18. dialogSignel = pyqtSignal(int, str)
  19. def __init__(self, parent=None):
  20. super(Dialogadd, self).__init__(parent)
  21. layout = QVBoxLayout(self)
  22. self.label = QLabel(self)
  23. self.lineEdit = QLineEdit(self)
  24. self.label.setText("请输入物料类型")
  25. layout.addWidget(self.label)
  26. layout.addWidget(self.lineEdit)
  27. buttons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self)
  28. buttons.accepted.connect(self.accept) # 点击ok
  29. buttons.rejected.connect(self.reject) # 点击cancel
  30. layout.addWidget(buttons)
  31. def accept(self): # 点击ok是发送内置信号
  32. material = self.lineEdit.text()
  33. if not material:
  34. return ;
  35. self.dialogSignel.emit(0, material)
  36. self.destroy()
  37. def reject(self): # 点击cancel时,发送自定义信号
  38. self.destroy()
  39. if __name__ == '__main__':
  40. import sys
  41. app = QApplication(sys.argv)
  42. Dialog = Dialogadd()
  43. Dialog.show()
  44. sys.exit(app.exec_())