# Dessiner une image en utilisant paintEvent from PySide import QtGui,QtCore import sys class ZoneDessin(QtGui.QWidget) : def __init__(self,parent=None) : super().__init__(parent) self.pixmap=QtGui.QPixmap("balle.png") self.posx=100 self.posy=100 self.dirx,self.diry=2,-2 self.timer=QtCore.QBasicTimer() self.timer.start(10,self) def timerEvent(self,e) : self.posx+=self.dirx self.posy+=self.diry self.repaint() if self.posx<15 or self.posx>self.width()-15 : self.dirx=-self.dirx if self.posy<15 or self.posy>self.height()-15 : self.diry=-self.diry def mousePressEvent(self,e) : if (self.posx-e.x())**2+(self.posy-e.y())**2<15**2 : if self.timer.isActive() : self.timer.stop() else : self.timer.start(10,self) def paintEvent(self,e) : p=QtGui.QPainter(self) p.drawPixmap(self.posx-16,self.posy-16,32,32,self.pixmap) class Fenetre(QtGui.QMainWindow): def __init__(self,parent=None) : super().__init__(parent) self.resize(420,420) self.setWindowTitle("Balle") dessin=ZoneDessin(self) dessin.setGeometry(10,10,400,400) app=QtGui.QApplication(sys.argv) frame=Fenetre() frame.show() sys.exit(app.exec_())