Created
October 19, 2011 17:52
-
-
Save skayred/1299107 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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