jiateng_ws/ui/luno_query_dialog_ui.py

347 lines
12 KiB
Python
Raw Permalink Normal View History

2025-07-19 13:17:24 +08:00
from PySide6.QtWidgets import (
QDialog, QLabel, QLineEdit, QComboBox, QPushButton,
QVBoxLayout, QHBoxLayout, QFrame, QTableWidget, QTableWidgetItem,
QHeaderView, QDateEdit, QApplication
)
from PySide6.QtCore import Qt, QDate
from PySide6.QtGui import QFont
class LunoQueryDialogUI(QDialog):
def __init__(self):
super().__init__()
self.setWindowTitle("炉号查询")
self.resize(1200, 600) # 调整宽度和高度
# 设置字体
self.normal_font = QFont("微软雅黑", 10)
self.title_font = QFont("微软雅黑", 10, QFont.Bold)
# 初始化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(10)
# 创建查询条件区域
self.create_query_frame()
# 创建结果表格
self.create_result_table()
# 创建按钮
self.create_buttons()
def create_query_frame(self):
"""创建查询条件区域"""
# 创建一个带边框的容器
query_frame = QFrame()
query_frame.setStyleSheet("""
QFrame {
border: 1px solid #e0e0e0;
background-color: white;
border-radius: 4px;
}
""")
# 容器的垂直布局
query_layout = QVBoxLayout(query_frame)
query_layout.setContentsMargins(15, 15, 15, 15)
query_layout.setSpacing(10)
# 第一行:日期范围和炉号
row1 = QHBoxLayout()
# 日期标签
date_label = QLabel("日期:")
date_label.setFont(self.normal_font)
date_label.setFixedWidth(40)
# 开始日期
self.start_date = QDateEdit()
self.start_date.setFont(self.normal_font)
self.start_date.setCalendarPopup(True)
self.start_date.setDate(QDate.currentDate().addDays(-7))
self.start_date.setFixedWidth(120)
self.start_date.setStyleSheet("""
QDateEdit {
border: 1px solid #e0e0e0;
padding: 4px;
border-radius: 4px;
}
""")
# 至标签
to_label = QLabel("至:")
to_label.setFont(self.normal_font)
to_label.setFixedWidth(20)
# 结束日期
self.end_date = QDateEdit()
self.end_date.setFont(self.normal_font)
self.end_date.setCalendarPopup(True)
self.end_date.setDate(QDate.currentDate())
self.end_date.setFixedWidth(120)
self.end_date.setStyleSheet("""
QDateEdit {
border: 1px solid #e0e0e0;
padding: 4px;
border-radius: 4px;
}
""")
# 炉号标签
luno_label = QLabel("炉号:")
luno_label.setFont(self.normal_font)
luno_label.setFixedWidth(50)
# 炉号输入框
self.luno_input = QLineEdit()
self.luno_input.setFont(self.normal_font)
self.luno_input.setStyleSheet("""
QLineEdit {
border: 1px solid #e0e0e0;
padding: 4px;
border-radius: 4px;
}
QLineEdit:focus {
border: 1px solid #66afe9;
}
""")
# 材质标签
material_label = QLabel("材质")
material_label.setFont(self.normal_font)
material_label.setFixedWidth(40)
# 材质下拉框
self.material_combo = QComboBox()
self.material_combo.setFont(self.normal_font)
self.material_combo.addItem("全部")
self.material_combo.setStyleSheet("""
QComboBox {
border: 1px solid #e0e0e0;
padding: 4px;
border-radius: 4px;
}
QComboBox::drop-down {
subcontrol-origin: padding;
subcontrol-position: top right;
width: 20px;
border-left: 1px solid #e0e0e0;
}
""")
# 规格标签
spec_label = QLabel("规格")
spec_label.setFont(self.normal_font)
spec_label.setFixedWidth(40)
# 规格输入框
self.spec_input = QLineEdit()
self.spec_input.setFont(self.normal_font)
self.spec_input.setStyleSheet("""
QLineEdit {
border: 1px solid #e0e0e0;
padding: 4px;
border-radius: 4px;
}
QLineEdit:focus {
border: 1px solid #66afe9;
}
""")
# 钢厂标签
steel_label = QLabel("钢厂")
steel_label.setFont(self.normal_font)
steel_label.setFixedWidth(40)
# 钢厂输入框
self.steel_input = QLineEdit()
self.steel_input.setFont(self.normal_font)
self.steel_input.setStyleSheet("""
QLineEdit {
border: 1px solid #e0e0e0;
padding: 4px;
border-radius: 4px;
}
QLineEdit:focus {
border: 1px solid #66afe9;
}
""")
# 查询按钮
self.query_button = QPushButton("查询")
self.query_button.setFont(self.normal_font)
self.query_button.setStyleSheet("""
QPushButton {
background-color: #0078d4;
color: white;
border: none;
border-radius: 4px;
padding: 6px 16px;
}
QPushButton:hover {
background-color: #106ebe;
}
QPushButton:pressed {
background-color: #005a9e;
}
""")
self.query_button.setFixedWidth(80)
# 添加组件到第一行布局
row1.addWidget(date_label)
row1.addWidget(self.start_date)
row1.addWidget(to_label)
row1.addWidget(self.end_date)
row1.addSpacing(20)
row1.addWidget(luno_label)
row1.addWidget(self.luno_input, 1)
row1.addSpacing(20)
row1.addWidget(material_label)
row1.addWidget(self.material_combo, 1)
row1.addSpacing(20)
row1.addWidget(spec_label)
row1.addWidget(self.spec_input, 1)
row1.addSpacing(20)
row1.addWidget(steel_label)
row1.addWidget(self.steel_input, 1)
row1.addSpacing(20)
row1.addWidget(self.query_button)
# 添加第一行到查询布局
query_layout.addLayout(row1)
# 将查询框架添加到主布局
self.main_layout.addWidget(query_frame)
def create_result_table(self):
"""创建结果表格"""
# 创建表格
self.result_table = QTableWidget()
self.result_table.setFont(self.normal_font)
# 设置表头样式
header = self.result_table.horizontalHeader()
header.setStyleSheet("""
QHeaderView::section {
background-color: #f5f5f5;
color: #333333;
padding: 5px;
border: 1px solid #e0e0e0;
font-weight: bold;
}
""")
# 设置表格样式
self.result_table.setStyleSheet("""
QTableWidget {
border: 1px solid #e0e0e0;
gridline-color: #e0e0e0;
selection-background-color: #0078d4;
selection-color: white;
}
QTableWidget::item {
padding: 5px;
border-bottom: 1px solid #e0e0e0;
}
""")
# 启用水平滚动条
self.result_table.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
# 设置表头固定宽度模式,确保所有列都能显示
header.setSectionResizeMode(QHeaderView.Fixed)
# 设置表格最小宽度,确保有足够空间显示滚动条
self.result_table.setMinimumWidth(800)
# 设置默认列宽
self.result_table.setColumnWidth(0, 60) # 序号
self.result_table.setColumnWidth(1, 100) # 日期
self.result_table.setColumnWidth(2, 120) # 炉号
self.result_table.setColumnWidth(3, 100) # 材质
self.result_table.setColumnWidth(4, 100) # 规格
self.result_table.setColumnWidth(5, 100) # 钢厂
self.result_table.setColumnWidth(6, 80) # 标准
self.result_table.setColumnWidth(7, 100) # 公司账套
self.result_table.setColumnWidth(8, 60) # C
self.result_table.setColumnWidth(9, 60) # Si
self.result_table.setColumnWidth(10, 60) # Mn
self.result_table.setColumnWidth(11, 60) # P
self.result_table.setColumnWidth(12, 60) # S
self.result_table.setColumnWidth(13, 60) # Ni
self.result_table.setColumnWidth(14, 60) # Cr
self.result_table.setColumnWidth(15, 60) # Ti
self.result_table.setColumnWidth(16, 60) # Mo
self.result_table.setColumnWidth(17, 60) # Cu
self.result_table.setColumnWidth(18, 80) # 其他
self.result_table.setColumnWidth(19, 100) # 抗拉强度
self.result_table.setColumnWidth(20, 80) # 延伸率
# 设置表格可以选择整行
self.result_table.setSelectionBehavior(QTableWidget.SelectRows)
# 设置表格只能单选
self.result_table.setSelectionMode(QTableWidget.SingleSelection)
# 添加表格到主布局
self.main_layout.addWidget(self.result_table, 1) # 1表示拉伸因子让表格占据更多空间
def create_buttons(self):
"""创建底部按钮"""
button_layout = QHBoxLayout()
# 确认和取消按钮
self.confirm_button = QPushButton("确认")
self.confirm_button.setFont(self.normal_font)
self.confirm_button.setStyleSheet("""
QPushButton {
background-color: #0078d4;
color: white;
border: none;
border-radius: 4px;
padding: 8px 16px;
font-weight: bold;
}
QPushButton:hover {
background-color: #106ebe;
}
QPushButton:pressed {
background-color: #005a9e;
}
""")
self.confirm_button.setFixedSize(100, 35)
self.cancel_button = QPushButton("取消")
self.cancel_button.setFont(self.normal_font)
self.cancel_button.setStyleSheet("""
QPushButton {
background-color: white;
color: #333333;
border: 1px solid #e0e0e0;
border-radius: 4px;
padding: 8px 16px;
font-weight: bold;
}
QPushButton:hover {
background-color: #f5f5f5;
}
QPushButton:pressed {
background-color: #e0e0e0;
}
""")
self.cancel_button.setFixedSize(100, 35)
# 添加按钮到布局
button_layout.addStretch()
button_layout.addWidget(self.confirm_button)
button_layout.addSpacing(30) # 添加30px的间距
button_layout.addWidget(self.cancel_button)
# 添加按钮布局到主布局
self.main_layout.addLayout(button_layout)