import sys
import PyQt4.QtGui as qtgui
import PyQt4.QtCore as qtcore

class CustomPixmapItem(qtgui.QGraphicsItem):
	def __init__(self,parent=None,scene=None):
		qtgui.QGraphicsPixmapItem.__init__(self,parent,scene)
		self.image=qtgui.QImage(200,200,qtgui.QImage.Format_ARGB32_Premultiplied)
		self.image.fill(0xffffffff)

	def drawPoint(self,x,y):
		painter=qtgui.QPainter()
		painter.begin(self.image)
		rect=qtcore.QRect(x,y,3,3)
		painter.fillRect(rect,qtgui.QColor(0,0,0))
		self.update(qtcore.QRectF(rect))

	def paint(self,painter,options,widget=None):
		rect=options.exposedRect
		print "Exposed Rect:", rect.x(), rect.y(), rect.width(), rect.height()
		# this I think should work, but doesn't since the rectangle never has anything in it
		painter.drawImage(options.exposedRect,self.image,options.exposedRect)

		# this alternate line works fine
		#painter.drawImage(qtcore.QPoint(0,0),self.image)

class CustomScene(qtgui.QGraphicsScene):
	def __init__(self,rect,parent=None):
		qtgui.QGraphicsScene.__init__(self,rect,parent)

	def mousePressEvent(self,event):
		for item in self.items():
			item.drawPoint(event.scenePos().x(),event.scenePos().y())
		self.update()

app=qtgui.QApplication(sys.argv)

window=qtgui.QMainWindow()
window.show()
window.resize(240,240)

scene=CustomScene(qtcore.QRectF(0,0,200,200))
scene.setBackgroundBrush(qtgui.QBrush(qtgui.QColor(255,255,255)))
scene.update()
view=qtgui.QGraphicsView(scene,window)

view.show()

window.setCentralWidget(view)

item=CustomPixmapItem(None,None)
scene.addItem(item)

app.exec_()