Skip to content

Instantly share code, notes, and snippets.

@skayred
Created October 19, 2011 17:52
Show Gist options
  • Save skayred/1299107 to your computer and use it in GitHub Desktop.
Save skayred/1299107 to your computer and use it in GitHub Desktop.
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class Window(QWidget):
def __init__(self):
QWidget.__init__(self)
self.points = []
def paintEvent(self, event):
painter = QPainter()
painter.begin(self)
painter.setPen(QPen(QBrush(Qt.red), 3))
for i in range(len(self.points) - 1):
now = self.points[i]
next = self.points[i + 1]
painter.drawLine(now, next)
painter.end()
def mousePressEvent(self, event):
self.points.append(event.pos())
def mouseMoveEvent(self, event):
self.points.append(event.pos())
self.update()
def sizeHint(self):
return QSize(500, 500)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment