我希望能够在使用PyQt编写的Python脚本中,通过鼠标点击绘制由多个点组成的线段。需要获取所有点的坐标,并且希望能够删除该线段。下面是我完成所有操作的脚本,但是还没有实现图形线段的绘制,它只是输出了所做的事情:
#!/usr/bin/python3
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class endomess(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.draw = False
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
if self.draw == False:
print('Starting to draw at', str(event.pos()))
self.draw = True
self.linePoints = []
elif self.draw == True:
print('Appending', str(event.pos()))
self.linePoints.append(event.pos())
elif event.button() == Qt.RightButton:
if self.draw == True:
print('Finished drawing. List of all points:', str(self.linePoints))
self.draw = False
def main(argv):
app = QApplication(argv, True)
wnd = endomess()
wnd.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main(sys.argv)
所以,这是我的问题:我该如何绘制可以通过上述脚本定义的线条?我已经查看了scribble.py和一些Qt绘画文档,但我不明白。可能对于更有经验的Qt用户来说,这不是问题?
感谢您提前提供所有帮助!