from PySide6.QtWidgets import ( QDialog, QLabel, QLineEdit, QComboBox, QPushButton, QVBoxLayout, QHBoxLayout, QFrame ) from PySide6.QtCore import Qt from PySide6.QtGui import QFont class UnloadingDialogUI(QDialog): def __init__(self): super().__init__() self.setWindowTitle("下料操作") self.setFixedSize(700, 250) # 增加宽度以适应较长的托盘类型选项 # 设置字体 self.normal_font = QFont("微软雅黑", 12) # 初始化UI self.init_ui() def init_ui(self): """初始化UI""" # 主布局 self.main_layout = QVBoxLayout(self) self.main_layout.setContentsMargins(20, 20, 20, 20) self.main_layout.setSpacing(0) # 移除布局间距 # 创建内容区域 self.create_content_frame() # 创建按钮 self.create_buttons() def create_content_frame(self): """创建内容区域""" # 创建一个带边框的容器 container = QFrame() container.setStyleSheet(""" QFrame { border: 1px solid #e0e0e0; background-color: white; } """) # 容器的垂直布局 container_layout = QVBoxLayout(container) container_layout.setContentsMargins(0, 0, 0, 0) container_layout.setSpacing(0) # 通用样式 label_style = """ QLabel { background-color: #f5f5f5; color: #333333; font-weight: bold; border: none; border-right: 1px solid #e0e0e0; border-bottom: 1px solid #e0e0e0; padding: 0 8px; } """ input_style = """ QLineEdit { border: none; border-right: 1px solid #e0e0e0; border-bottom: 1px solid #e0e0e0; background-color: white; selection-background-color: #0078d4; padding: 0 8px; } QLineEdit:focus { background-color: #f8f8f8; } """ value_style = """ QLabel { background-color: white; border: none; border-right: 1px solid #e0e0e0; border-bottom: 1px solid #e0e0e0; padding: 0 8px; } """ # 第一行:托盘号 row1 = QHBoxLayout() row1.setSpacing(0) self.tray_label = QLabel("托盘号") self.tray_label.setFont(self.normal_font) self.tray_label.setStyleSheet(label_style) self.tray_label.setFixedWidth(100) self.tray_label.setFixedHeight(45) self.tray_input = QLineEdit() self.tray_input.setFont(self.normal_font) self.tray_input.setPlaceholderText("请扫描托盘号") self.tray_input.setStyleSheet(input_style) self.tray_input.setFixedHeight(45) row1.addWidget(self.tray_label) row1.addWidget(self.tray_input, 1) container_layout.addLayout(row1) # 添加水平分隔布局 split_layout = QHBoxLayout() split_layout.setSpacing(0) left_split = QLabel() left_split.setFixedWidth(100) left_split.setFixedHeight(1) left_split.setStyleSheet("background-color: #e0e0e0;") right_split = QLabel() right_split.setFixedHeight(1) right_split.setStyleSheet("background-color: #e0e0e0;") split_layout.addWidget(left_split) split_layout.addWidget(right_split, 1) container_layout.addLayout(split_layout) # 第二行:托盘类型和托盘层数 row2 = QHBoxLayout() row2.setSpacing(0) # 托盘类型部分 pallet_type_layout = QHBoxLayout() pallet_type_layout.setSpacing(0) self.pallet_type_label = QLabel("托盘类型") self.pallet_type_label.setFont(self.normal_font) self.pallet_type_label.setStyleSheet(label_style) self.pallet_type_label.setFixedWidth(100) self.pallet_type_label.setFixedHeight(45) self.pallet_type_input = QComboBox() self.pallet_type_input.setStyleSheet("border: none; padding: 5px 10px;") self.pallet_type_input.setFont(QFont("微软雅黑", 12)) self.pallet_type_input.setEditable(True) # 允许手动输入 self.pallet_type_input.setFixedHeight(45) self.pallet_type_input.setInsertPolicy(QComboBox.NoInsert) # 不自动插入用户输入到列表中 self.pallet_type_input.setMaxVisibleItems(10) # 设置下拉框最多显示10个项目 self.pallet_type_input.completer().setCaseSensitivity(Qt.CaseInsensitive) # 设置补全不区分大小写 self.pallet_type_input.completer().setFilterMode(Qt.MatchContains) # 设置模糊匹配模式 pallet_type_layout.addWidget(self.pallet_type_label) pallet_type_layout.addWidget(self.pallet_type_input, 1) # 托盘层数部分 tier_layout = QHBoxLayout() tier_layout.setSpacing(0) self.tier_label = QLabel("托盘层数") self.tier_label.setFont(self.normal_font) self.tier_label.setStyleSheet(label_style) self.tier_label.setFixedWidth(100) self.tier_label.setFixedHeight(45) self.tier_input = QLineEdit() self.tier_input.setFont(self.normal_font) self.tier_input.setStyleSheet(""" QLineEdit { border: none; border-right: 1px solid #e0e0e0; border-bottom: 1px solid #e0e0e0; background-color: white; selection-background-color: #0078d4; padding: 0 8px; } QLineEdit:focus { background-color: #f8f8f8; } """) self.tier_input.setFixedHeight(45) self.tier_input.setPlaceholderText("请输入层数") tier_layout.addWidget(self.tier_label) tier_layout.addWidget(self.tier_input, 1) row2.addLayout(pallet_type_layout, 1) row2.addLayout(tier_layout, 1) container_layout.addLayout(row2) # 添加水平分隔布局 split_layout2 = QHBoxLayout() split_layout2.setSpacing(0) left_split2 = QLabel() left_split2.setFixedWidth(100) left_split2.setFixedHeight(1) left_split2.setStyleSheet("background-color: #e0e0e0;") right_split2 = QLabel() right_split2.setFixedHeight(1) right_split2.setStyleSheet("background-color: #e0e0e0;") split_layout2.addWidget(left_split2) split_layout2.addWidget(right_split2, 1) container_layout.addLayout(split_layout2) # 第三行:轴型和材质 row3 = QHBoxLayout() row3.setSpacing(0) axis_layout = QHBoxLayout() axis_layout.setSpacing(0) self.axis_label = QLabel("轴型") self.axis_label.setFont(self.normal_font) self.axis_label.setStyleSheet(label_style) self.axis_label.setFixedWidth(100) self.axis_label.setFixedHeight(40) self.axis_value = QLabel("--") self.axis_value.setFont(self.normal_font) self.axis_value.setStyleSheet(value_style) self.axis_value.setFixedHeight(40) axis_layout.addWidget(self.axis_label) axis_layout.addWidget(self.axis_value, 1) tier_layout = QHBoxLayout() tier_layout.setSpacing(0) self.material_tier_label = QLabel("材质") self.material_tier_label.setFont(self.normal_font) self.material_tier_label.setStyleSheet(label_style) self.material_tier_label.setFixedWidth(100) self.material_tier_label.setFixedHeight(40) self.material_tier_value = QLineEdit() self.material_tier_value.setFont(self.normal_font) self.material_tier_value.setStyleSheet(""" QLineEdit { padding: 5px; background-color: white; color: #333333; } QLineEdit:focus { border: 1px solid #66afe9; outline: none; } """) self.material_tier_value.setFixedHeight(40) self.material_tier_value.setPlaceholderText(" -- ") tier_layout.addWidget(self.material_tier_label) tier_layout.addWidget(self.material_tier_value, 1) row3.addLayout(axis_layout, 1) row3.addLayout(tier_layout, 1) container_layout.addLayout(row3) # 添加水平分隔布局 split_layout3 = QHBoxLayout() split_layout3.setSpacing(0) left_split3 = QLabel() left_split3.setFixedWidth(100) left_split3.setFixedHeight(1) left_split3.setStyleSheet("background-color: #e0e0e0;") right_split3 = QLabel() right_split3.setFixedHeight(1) right_split3.setStyleSheet("background-color: #e0e0e0;") split_layout3.addWidget(left_split3) split_layout3.addWidget(right_split3, 1) container_layout.addLayout(split_layout3) # 第四行:数量和重量 row4 = QHBoxLayout() row4.setSpacing(0) quantity_layout = QHBoxLayout() quantity_layout.setSpacing(0) self.quantity_label = QLabel("数量") self.quantity_label.setFont(self.normal_font) self.quantity_label.setStyleSheet(label_style) self.quantity_label.setFixedWidth(100) self.quantity_label.setFixedHeight(40) self.quantity_value = QLabel("--") self.quantity_value.setFont(self.normal_font) self.quantity_value.setStyleSheet(value_style) self.quantity_value.setFixedHeight(40) quantity_layout.addWidget(self.quantity_label) quantity_layout.addWidget(self.quantity_value, 1) weight_layout = QHBoxLayout() weight_layout.setSpacing(0) self.weight_label = QLabel("重量") self.weight_label.setFont(self.normal_font) self.weight_label.setStyleSheet(label_style) self.weight_label.setFixedWidth(100) self.weight_label.setFixedHeight(40) self.weight_value = QLabel("--") self.weight_value.setFont(self.normal_font) self.weight_value.setStyleSheet(value_style) self.weight_value.setFixedHeight(40) weight_layout.addWidget(self.weight_label) weight_layout.addWidget(self.weight_value, 1) row4.addLayout(quantity_layout, 1) row4.addLayout(weight_layout, 1) container_layout.addLayout(row4) # 添加水平分隔布局 split_layout4 = QHBoxLayout() split_layout4.setSpacing(0) left_split4 = QLabel() left_split4.setFixedWidth(100) left_split4.setFixedHeight(1) left_split4.setStyleSheet("background-color: #e0e0e0;") right_split4 = QLabel() right_split4.setFixedHeight(1) right_split4.setStyleSheet("background-color: #e0e0e0;") split_layout4.addWidget(left_split4) split_layout4.addWidget(right_split4, 1) container_layout.addLayout(split_layout4) # 添加弹性空间 container_layout.addStretch() # 将容器添加到主布局 self.main_layout.addWidget(container) def create_buttons(self): """创建按钮""" # 按钮布局 button_layout = QHBoxLayout() button_layout.setContentsMargins(0, 20, 0, 0) button_layout.setSpacing(10) # 确认按钮 self.confirm_button = QPushButton("确认") self.confirm_button.setFont(self.normal_font) self.confirm_button.setStyleSheet(""" QPushButton { background-color: #fff8e1; border: 1px solid #ffc107; padding: 8px 16px; font-weight: bold; border-radius: 4px; } QPushButton:hover { background-color: #fff3e0; } """) # 取消按钮 self.cancel_button = QPushButton("取消") self.cancel_button.setFont(self.normal_font) self.cancel_button.setStyleSheet(""" QPushButton { background-color: #f5f5f5; border: 1px solid #e0e0e0; padding: 8px 16px; font-weight: bold; border-radius: 4px; } QPushButton:hover { background-color: #eeeeee; } """) # 添加按钮到布局 button_layout.addStretch() button_layout.addWidget(self.confirm_button) button_layout.addWidget(self.cancel_button) # 将按钮布局添加到主布局 self.main_layout.addLayout(button_layout)