[PyQt] Drawing lines in PyQt in real time

sw33tz nyavuz.nm20 at gmail.com
Sun Apr 24 13:25:23 BST 2016


I'm making an application and I want to connect certain items in the
QGraphicsScene by using lines. I want this done in real time, so while I'm
holding the mouse down and trying to draw the line I want to see the line
being drawn. I've written some code to allow this but the problem with this
code is that it keeps on clearing everything and I dont know a way around
this. Any help would be much appreciated. 


class graphicsScene(QtGui.QGraphicsScene, QtGui.QWidget): 
    self.pen = QtGui.QPen(QtCore.Qt.black, 3, QtCore.Qt.SolidLine) 


    def mousePressEvent(self, event): 
        if connectLine_cs == 1: 
            self.cursorStartPosition = event.scenePos() 
            self.start =
QtCore.QPoint(self.cursorStartPosition.x(),self.cursorStartPosition.y()) 

    def mouseMoveEvent(self, event): 
        if connectLine_cs == 1: 
             self.cursorCurrentPosition = event.scenePos() 
             current =
QtCore.QPointF(self.cursorCurrentPosition.x(),self.cursorCurrentPosition.y()) 
             self.clear() 
             link = QtGui.QGraphicsLineItem(QtCore.QLineF(self.start,
current)) 
             link.setPen(self.pen) 
             self.addItem(link)



--
View this message in context: http://python.6.x6.nabble.com/Drawing-lines-in-PyQt-in-real-time-tp5189233.html
Sent from the PyQt mailing list archive at Nabble.com.


More information about the PyQt mailing list