guys.I have a QLabel with a pixmap-a PNG image(typically a football playground) and I wanna draw some rectangels(represent some robots) on the playground,which I use the painter class to draw actually on its container-the QLabel. But when I use the painter to draw the REC,the RECT showed but the image just turned to blank.I don't know why it failed, and could u plz do me a favor and give me some hints on that?
class FieldLabel(QtGui.QLabel):
positionData = {"1":{"x":13,"y":20},"2":{"x":28,"y":19},"3":{"x":17,"y":21}}
def __init__(self, image_path):
QtGui.QLabel.__init__(self)
self.field = QtGui.QPixmap("field.png")
self.setPixmap(self.field.scaled(self.size(),
QtCore.Qt.KeepAspectRatio))
self.setSizePolicy(QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Expanding)
self.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)
def paintEvent(self,e):
draw = QtGui.QPainter()
draw.begin(self)
draw.setBrush(QtCore.Qt.NoBrush)
draw.setPen(QtCore.Qt.blue)
draw.drawRect(0,0,10,10)
draw.end()