<>使用pyqt5设置按钮大小、布局、颜色等

最近在用pyqt5做前段的界面,想着怎么把界面做的更有趣生动一点。

看下面的代码你就理解了
vbox = QVBoxLayout() vbox.setAlignment(Qt.AlignVCenter) self.people_choose =
QComboBox() self.people_choose.setFont(QFont('微软雅黑', 15)) self.people_choose.
setStyleSheet("QComboBox{background:white}") self.people_choose.setMinimumSize(
175, 30) self.people_choose.addItem('未选择使用人员') self.people_choose.addItems([
"考核人员", "管理人员"]) self.people_choose.currentIndexChanged.connect(self.
changePeople) vbox.addWidget(self.people_choose) # 选择课程按钮 courses = self.
getAllSubjects() self.course_choose = QComboBox() self.course_choose.setFont(
QFont('微软雅黑', 15)) self.course_choose.setStyleSheet(
"QComboBox{background:white}") self.course_choose.setMinimumSize(175, 30) #
self.course_choose.setMaximumSize(175, 30) self.course_choose.addItem('未选择考核课程')
self.course_choose.addItems(courses) self.course_choose.currentIndexChanged.
connect(self.changeCourse) vbox.addWidget(self.course_choose) # 考核评判按钮
btnExamine= QPushButton('考核评判') btnExamine.setMinimumHeight(170) btnExamine.
setFont(QFont('微软雅黑', 25)) btnExamine.clicked.connect(self.onBtnExamine)
btnExamine.setStyleSheet(
'''QPushButton{background:#54FF9F;border-radius:5px;}QPushButton:hover{background:LawnGreen;}'''
) # 设置默认按钮颜色以及鼠标在悬浮在上面的颜色 # 颜色设置可以参考RGB对照表来设置你喜欢的颜色 vbox.addWidget(btnExamine)
# 历史记录按钮 self.btnHistory = QPushButton('历史记录') self.btnHistory.setMinimumHeight(
170) self.btnHistory.setFont(QFont('微软雅黑', 25)) self.btnHistory.clicked.connect(
self.onBtnHistory) self.btnHistory.setStyleSheet(
'''QPushButton{background:#54FF9F;border-radius:5px;}QPushButton:hover{background:LawnGreen;}'''
) vbox.addWidget(self.btnHistory) # 语音标注按钮 self.btnMark = QPushButton('语音标注')
self.btnMark.setMinimumHeight(170) self.btnMark.setFont(QFont('微软雅黑', 25)) self.
btnMark.clicked.connect(self.onBtnMark) self.btnMark.setStyleSheet(
'''QPushButton{background:#FFC0CB;border-radius:5px;}QPushButton:hover{background:HotPink;}'''
) vbox.addWidget(self.btnMark) # 机器学习按钮 self.btnTrain = QPushButton('机器学习') self
.btnTrain.setMinimumHeight(170) self.btnTrain.setFont(QFont('微软雅黑', 25)) self.
btnTrain.clicked.connect(self.onBtnTrain) self.btnTrain.setStyleSheet(
'''QPushButton{background:#FFC0CB;border-radius:5px;}QPushButton:hover{background:HotPink;}'''
) vbox.addWidget(self.btnTrain)
实际使用效果
鼠标悬停在按钮上面会变色

技术
今日推荐
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:766591547
关注微信