前言
在用pyqt5实现GUI时,一个界面放置图片太多,不是很美观。想做轮播效果,设定一定时间间隔对文件夹内图片轮流显示,并且点击相应图片能够弹出原图。
实现效果
具体代码
轮播效果:定时器实现
self.timer1=QTimer(self)
self.timer1.timeout.connect(self.timer_TimeOut)
self.timer1.start(2000)#图片间隔时长
def timer_TimeOut(self):
self.n+=1
if self.n>4:
self.n=1
self.lu ="./img/icon" +str(self.n)+".png"
self.pm = QPixmap(self.lu)
self.lbpic.setPixmap(self.pm)
点击事件:最初想通过Qlabel的鼠标点击事件绑定打开原图的。发现
Qlabel没有clicked,自己重写一个myLabel类继承QLabel。在通过信号槽机制实现。
class myLabel(QLabel):
_signal = pyqtSignal(str)