class EmployeeInfoWindow(QWidget): def init(self, user_id, stacked_widget): super().init() self.user_id = user_id self.stacked_widget = stacked_widget self.initUI() def initUI(self): # 连接数据库,获取员工信息 conn = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', database='jj_tset') cursor = conn.cursor() cursor.execute("SELECT * FROM employee_table WHERE user_id='%s'" % self.user_id) result = cursor.fetchone() conn.close() # 创建用于显示员工信息的控件 info_label = QLabel("员工信息", self) info_label.move(100, 50) info_label.setStyleSheet("font-size: 24px; color: black; background-color: #eee; border-radius: 10px;") id_label = QLabel("员工ID:" + result[0], self) id_label.move(70, 100) id_label.setStyleSheet("font-size: 18px; color: black;") name_label = QLabel("姓名:" + str(result[1]), self) name_label.move(70, 150) name_label.setStyleSheet("font-size: 18px; color: black;") six_label = QLabel("性别:" + result[2], self) six_label.move(70, 200) six_label.setStyleSheet("font-size: 18px; color: black;") sfz_label = QLabel("身份证:" + str(result[3]), self) sfz_label.move(70, 250) sfz_label.setStyleSheet("font-size: 18px; color: black;") tel_label = QLabel("电话:" + result[4], self) tel_label.move(70, 300) tel_label.setStyleSheet("font-size: 18px; color: black;") # 创建数字显示框 self.value_label = QLabel(self) self.value_label.setGeometry(500, 100, 200, 50) self.value_label.setStyleSheet("font-size: 24px; color: black; background-color: #eee; border-radius: 10px;") self.lcd_1 = QLCDNumber(self) # 2 self.lcd_1.setSegmentStyle(QLCDNumber.Flat) # self.lcd_2.setSmallDecimalPoint(True) self.lcd_1.setDigitCount(10) self.lcd_1.display(0.123456789) self.v_layout = QVBoxLayout() self.v_layout.addWidget(self.lcd_1) self.setLayout(self.v_layout) # 创建返回按钮 back_button = QPushButton('返回', self) back_button.setGeometry(600, 400, 100, 50) back_button.clicked.connect(self.backToLoginWindow) # 设置窗口大小和标题 self.setFixedSize(800, 500) self.setWindowTitle('员工信息')调整lcd_1在右边,数字显示加外框
时间: 2024-01-21 17:16:03 浏览: 98
可以把数字显示框和外框放到一个QWidget中,然后使用QHBoxLayout将数字显示框和外框放在一起,并设置外框的样式。具体代码可以参考下面的示例:
```python
class EmployeeInfoWindow(QWidget):
def __init__(self, user_id, stacked_widget):
super().__init__()
self.user_id = user_id
self.stacked_widget = stacked_widget
self.initUI()
def initUI(self):
# 连接数据库,获取员工信息
conn = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', database='jj_tset')
cursor = conn.cursor()
cursor.execute("SELECT * FROM employee_table WHERE user_id='%s'" % self.user_id)
result = cursor.fetchone()
conn.close()
# 创建用于显示员工信息的控件
info_label = QLabel("员工信息", self)
info_label.move(100, 50)
info_label.setStyleSheet("font-size: 24px; color: black; background-color: #eee; border-radius: 10px;")
id_label = QLabel("员工ID:" + result[0], self)
id_label.move(70, 100)
id_label.setStyleSheet("font-size: 18px; color: black;")
name_label = QLabel("姓名:" + str(result[1]), self)
name_label.move(70, 150)
name_label.setStyleSheet("font-size: 18px; color: black;")
six_label = QLabel("性别:" + result[2], self)
six_label.move(70, 200)
six_label.setStyleSheet("font-size: 18px; color: black;")
sfz_label = QLabel("身份证:" + str(result[3]), self)
sfz_label.move(70, 250)
sfz_label.setStyleSheet("font-size: 18px; color: black;")
tel_label = QLabel("电话:" + result[4], self)
tel_label.move(70, 300)
tel_label.setStyleSheet("font-size: 18px; color: black;")
# 创建数字显示框和外框
value_widget = QWidget(self)
value_widget.setGeometry(500, 100, 200, 50)
self.lcd_1 = QLCDNumber(value_widget)
self.lcd_1.setSegmentStyle(QLCDNumber.Flat)
self.lcd_1.setDigitCount(10)
self.lcd_1.display(0.123456789)
hbox_layout = QHBoxLayout(value_widget)
hbox_layout.addWidget(self.lcd_1)
hbox_layout.setContentsMargins(0, 0, 0, 0)
hbox_layout.setSpacing(0)
value_widget.setStyleSheet('''
background-color: #eee;
border-radius: 10px;
border: 2px solid black;
''')
# 创建返回按钮
back_button = QPushButton('返回', self)
back_button.setGeometry(600, 400, 100, 50)
back_button.clicked.connect(self.backToLoginWindow)
# 设置窗口大小和标题
self.setFixedSize(800, 500)
self.setWindowTitle('员工信息')
```
这样就可以将数字显示框放在右边,并加上外框了。注意,我这里使用的是QWidget来包含数字显示框和外框,而不是QLabel。因为QLabel默认会设置自己的大小和位置,如果想要自定义大小和位置需要修改它的属性,比较麻烦。而QWidget则没有这个问题,可以更灵活地调整大小和位置。
阅读全文