Here are a few code snippets I had to search for . This is for my future reference and for any one who might needing it.
1 . First of all , a simple concept that I did not understand before.
app = QtGui.QApplication(sys.argv) #Main Class here sys.exit(app.exec_()) #app.exec_() runs the whole qt loop till you provide it with the exit method.
2 . And I had just started this thing called QtGraphicsView . It seems really complicated and this is what Ive understood till now.
#Inheriting the class QGraphicsView class Example(QtGui.QGraphicsView): def __init__ (self): super(Example , self).__init__() #As usual when you want to inherit the __init__ method of the class //Adding QGraphicsScene to your QGraphicsView which is the parent self.scene = QtGui.QGraphicsScene(self)
3 . And now you can add lines , ellipses and other stuff to your self.scene [For now I know just lines and ellipses]
self.line = QtGui.QGraphicsLineItem(self.startx , self.starty , self.endx , self.endy) //initial and final positions of the line. self.scene.addItem(self.line)
4 . And for tracking the position of the mouse , the following functions come in handy
def mousePressEvent(self , event): //event is actually the class mousePressEvent self.startx = event.x() self.starty = event.y()
The same applies for mouseReleaseEvents and mouseMoveEvents , the difference between event.x() and event.y() give the co-ordinates when the mouse is released or moved.
And if you want the clear the QGraphicsScene , what do you have to do?
Simple , self.scene.clear()
Thats all for now.