【发布时间】:2017-01-28 02:28:48
【问题描述】:
我想使用 PyQt 在 Python 脚本中通过鼠标单击绘制一条由多个点组成的线。我需要所有的 ponts 坐标,并且我希望能够删除这条线。这是我的脚本完成所有工作,除了图形线条图本身,它只是打印它所做的:
#!/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 经验丰富的人来说,这可能不是问题?
提前感谢所有帮助!
【问题讨论】: