91 lines
3.2 KiB
Python
91 lines
3.2 KiB
Python
|
|
from PySide6.QtWidgets import QFrame, QLabel, QGridLayout
|
||
|
|
from PySide6.QtCore import Qt
|
||
|
|
from PySide6.QtGui import QFont
|
||
|
|
|
||
|
|
class InspectionCard(QFrame):
|
||
|
|
def __init__(self, data, parent=None):
|
||
|
|
super().__init__(parent)
|
||
|
|
self.data = data
|
||
|
|
self.init_ui()
|
||
|
|
|
||
|
|
def init_ui(self):
|
||
|
|
self.setFrameShape(QFrame.Box)
|
||
|
|
self.setLineWidth(1)
|
||
|
|
# Black border
|
||
|
|
self.setStyleSheet("""
|
||
|
|
InspectionCard {
|
||
|
|
background-color: white;
|
||
|
|
border: 1px solid black;
|
||
|
|
margin-bottom: 10px;
|
||
|
|
}
|
||
|
|
QLabel {
|
||
|
|
font-family: 'Microsoft YaHei';
|
||
|
|
font-size: 16px;
|
||
|
|
padding-left: 8px;
|
||
|
|
padding-right: 5px;
|
||
|
|
padding-top: 5px;
|
||
|
|
padding-bottom: 5px;
|
||
|
|
color: black;
|
||
|
|
qproperty-alignment: 'AlignLeft | AlignVCenter';
|
||
|
|
}
|
||
|
|
.HeaderLabel {
|
||
|
|
font-weight: bold;
|
||
|
|
qproperty-alignment: 'AlignCenter';
|
||
|
|
padding-left: 5px;
|
||
|
|
}
|
||
|
|
""")
|
||
|
|
|
||
|
|
layout = QGridLayout(self)
|
||
|
|
layout.setSpacing(0)
|
||
|
|
layout.setContentsMargins(0, 0, 0, 0)
|
||
|
|
cell_style = "border: 1px solid black; padding: 4px;"
|
||
|
|
|
||
|
|
# Function to add cell
|
||
|
|
def add_cell(text, row, col, row_span=1, col_span=1, is_header=False):
|
||
|
|
lbl = QLabel(text)
|
||
|
|
if is_header:
|
||
|
|
lbl.setAlignment(Qt.AlignCenter)
|
||
|
|
lbl.setProperty("class", "HeaderLabel")
|
||
|
|
lbl.setStyleSheet(cell_style + "font-weight: bold;")
|
||
|
|
else:
|
||
|
|
lbl.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
|
||
|
|
lbl.setStyleSheet(cell_style)
|
||
|
|
layout.addWidget(lbl, row, col, row_span, col_span)
|
||
|
|
|
||
|
|
add_cell("日期", 0, 0, 1, 1, True)
|
||
|
|
add_cell(self.data.get("date", ""), 0, 1, 1, 3)
|
||
|
|
add_cell("检验员", 0, 4, 1, 1, True)
|
||
|
|
add_cell(self.data.get("inspector", ""), 0, 5, 1, 1)
|
||
|
|
|
||
|
|
add_cell("工程号", 1, 0, 1, 1, True)
|
||
|
|
add_cell(self.data.get("batch_no", ""), 1, 1, 1, 3)
|
||
|
|
add_cell("规格", 1, 4, 1, 1, True)
|
||
|
|
add_cell(self.data.get("spec", ""), 1, 5, 1, 1)
|
||
|
|
|
||
|
|
add_cell("炉号1", 2, 0, 1, 1, True)
|
||
|
|
add_cell(self.data.get("heat_number", ""), 2, 1, 1, 2)
|
||
|
|
add_cell("材质1", 2, 3, 1, 1, True)
|
||
|
|
add_cell(self.data.get("cz", ""), 2, 4, 1, 2)
|
||
|
|
|
||
|
|
add_cell("炉号2", 3, 0, 1, 1, True)
|
||
|
|
add_cell(self.data.get("heat_number2", ""), 3, 1, 1, 2)
|
||
|
|
add_cell("材质2", 3, 3, 1, 1, True)
|
||
|
|
add_cell(self.data.get("cz2", ""), 3, 4, 1, 2)
|
||
|
|
|
||
|
|
layout.setSpacing(0)
|
||
|
|
|
||
|
|
for i in range(layout.count()):
|
||
|
|
widget = layout.itemAt(i).widget()
|
||
|
|
r, c, rs, cs = layout.getItemPosition(i)
|
||
|
|
|
||
|
|
style = "border-right: 1px solid black; border-bottom: 1px solid black; padding: 4px;"
|
||
|
|
if r == 0:
|
||
|
|
style += "border-top: 1px solid black;"
|
||
|
|
if c == 0:
|
||
|
|
style += "border-left: 1px solid black;"
|
||
|
|
|
||
|
|
if widget.property("class") == "HeaderLabel":
|
||
|
|
style += "font-weight: bold;"
|
||
|
|
|
||
|
|
widget.setStyleSheet(style)
|