pyqt - Why the pixmap(a football field image) disappear when I try to draw something on its QLabel? -
guys.i have qlabel pixmap-a png image(typically football game playground) , wanna draw rectangels(represent robots) on playground,which utilize painter class draw on container-the qlabel. when utilize painter draw rec,the rect showed image turned blank.i don't know why failed, , u plz me favor , give me 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()
paintevent
responsible drawing in widget. since you're overriding it, qlabel
's default implementation, draws qpixmap
, not invoked.
so, first should allow qlabel
painting, can paint on like:
def paintevent(self,e): # phone call base of operations implementation paint normal interface super(fieldlabel, self).paintevent(e) # paint on draw = qtgui.qpainter() draw.begin(self) draw.setbrush(qtcore.qt.nobrush) draw.setpen(qtcore.qt.blue) draw.drawrect(0,0,10,10) draw.end()
pyqt pyqt4 qpainter qpixmap
No comments:
Post a Comment