from PyQt4.QtGui import *
from PyQt4.QtCore import *
def __init__(self, parent = None):
super(GraphicsScene, self).__init__(parent)
self.setSceneRect(0, 0, 600, 500)
self.
setBackgroundBrush(QColor(242,
251,
235))
def mousePressEvent(self, e):
self.pointBegin = self.pointEnd = e.pos()
self.addItem(self.line)
def mouseMoveEvent(self, e):
self.pointEnd = e.pos()
self.
line.
setLine(QLineF(self.
pointBegin, self.
pointEnd))
def mouseReleaseEvent(self, e):
self.
line.
setLine(QLineF(self.
pointBegin, self.
pointEnd))
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class GraphicsScene(QGraphicsScene):
def __init__(self, parent = None):
super(GraphicsScene, self).__init__(parent)
self.setSceneRect(0, 0, 600, 500)
self.setBackgroundBrush(QColor(242, 251, 235))
def mousePressEvent(self, e):
self.pointBegin = self.pointEnd = e.pos()
self.line = QGraphicsLineItem(QLineF(self.pointBegin, self.pointEnd))
self.line.setFlags(QGraphicsItem.ItemIsMovable)
self.addItem(self.line)
def mouseMoveEvent(self, e):
self.pointEnd = e.pos()
self.line.setLine(QLineF(self.pointBegin, self.pointEnd))
def mouseReleaseEvent(self, e):
self.line.setLine(QLineF(self.pointBegin, self.pointEnd))
To copy to clipboard, switch view to plain text mode
Bookmarks