self.pictureButton_1.setFixedSize(10, 10)
self.pictureButton_2.setStyleSheet(
'''QPushButton{background:#FFFFFF;border-radius:5px;}QPushButton:hover{background:red;}''')
def changePicture1(self):
self.pictureButton_1.setStyleSheet('''QPushButton{background:#FF0000;border-radius:5px;}''')
self.pictureButton_2.setStyleSheet('''QPushButton{background:#FFFFFF;border-radius:5px;}''')
self.pictureButton_3.setStyleSheet('''QPushButton{background:#FFFFFF;border-radius:5px;}''')
self.pictureButton_4.setStyleSheet('''QPushButton{background:#FFFFFF;border-radius:5px;}''')
self.label.setPixmap(QtGui.QPixmap("images/carousel/1.png"))
点击按钮之后,其他按钮变成白色,被点击按钮变为红色,并且更换图片,图片是在label组件中显示
联系方式

本文介绍了如何通过Python实现点击事件,使得四个按钮中的一个变红并切换背景颜色,同时在Label组件中显示预设图片。代码展示了如何使用QPushButton和QLabel进行界面交互,包括设置样式和图片显示。
1095

被折叠的 条评论
为什么被折叠?



