我是 Python 新手。我用固定坐标绘制了多边形和圆。现在我想使用鼠标将这个多边形和圆圈移动到窗口上的其他位置。请指导我该怎么做?
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class MyFrame(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self)
def paintEvent(self, event=None):
paint=QPainter(self)
paint.setPen(QPen(QColor(Qt.green).dark(150),1,Qt.SolidLine))
segColor=QColor(Qt.green).dark(150)
paint.setBrush(segColor)
paint.setBrushOrigin(QPoint(225,225))
polygon=QPolygon([QPoint(250,175), QPoint(265,175), QPoint(250,190), QPoint(265,190),QPoint(250,175)])
paint.drawPolygon(polygon)
paint.setPen(QPen(QColor(Qt.red),1,Qt.SolidLine))
paint.setBrush(QBrush(Qt.NoBrush))
polygon1=QPolygon([QPoint(250,300), QPoint(250,500), QPoint(350,500), QPoint(350,300)])
paint.drawPolyline(polygon1)
paint.drawEllipse(50,50,50,50)
app=QApplication(sys.argv)
f=MyFrame()
f.show()
app.exec_()