[PyQt] Fade effect a widget on top of another widget

Nicola Murino lists at svrinformatica.it
Tue Aug 18 16:25:31 BST 2009


Hi all,

I'm trying to make a fade effect as explained here:

http://doc.trolltech.com/qq/qq16-fader.html
http://labs.trolltech.com/blogs/2007/08/21/fade-effects-a-blast-from-the-past/

I have a main windows and I change the centralwidget on some user action so I do somenthing like:

self.setCentralWidget(newwidget)

I would like to have a fade effect on widget change so I tryed to do a FaderWidget and call something like:

self.setCentralWidget(FaderWidget(newwidget))

this is my not working attempt for FaderWidget:

class widgetFader(QWidget):
	def __init__(self,faded,parent=None):
		super(widgetFader,self).__init__(parent)
		faded.setupUi(faded)
		self.timeline=QTimeLine(3000,self)
		self.connect(self.timeline,  SIGNAL("frameChanged(int)"), SLOT("update()"))
		self.timeline.setFrameRange(0,100)
		self.timeline.setCurveShape(QTimeLine.EaseInOutCurve)
		if faded:
			self.startBrush=faded.palette().window()
		else:
			self.startBrush=Qt.white
		
	def startAnimation(self):
		self.timeline.start()
		
	def paintEvent(self,event):
		painter=QPainter(self)
		frame=self.timeline.currentFrame()
		#print frame/100.0
		painter.setOpacity(frame/100.0)
		painter.fillRect(self.rect(),self.startBrush)
		if frame>=100:
			self.close()

what's wrong? waht is the right way to have a fader widget?

thanks
Nicola


More information about the PyQt mailing list