tags:

views:

40

answers:

1

hello
im trying to expand the pyqt image veiwer example to have a feature of drawing over images
i added a couple of tested functions that takes mouse events and draw over image
in the image viewer example my i chosed my painter to paint over imageLabel's pixmap

def mousMoveEvent(self,event):
painter = QtGui.QPainter(self.imageLabel.pixmap()) painter.setPen(QtGui.QPen (self.chosenColor,self.chosenWidth,Qt.solidLine,Qt.RoundCap,Qt.RoundJoin)) painter.drawLine(self.laspoint,event.pos())

. . .

the problem is : it's not drawing over pixmap at all.. it shows image ,, zoom , does everything but drawing is not working.. am i doing anything wrong? i've been trying for 3 days withought a result . does anyone have a better idea for it ?
thanks in advance

+1  A: 

Start off by just capturing mouse events and displaying the results using print statements to make sure you are getting the mouse data correctly. The next step is to use that mouse data and mouse events to feed into the drawing routines.

While it doesn't include taking mouse input, this tutorial on drawing in PyQt should point you in the right direction in terms of using the API to create drawings. Try drawing imperatively, i.e. not based on mouse input and check it display correctly.

Finally, you should be able to bring the two together, using the mouse events and data to drive the drawing routines.

Simon Hibbs
i did that already , it does print mouse events , and it draws over other windows. no problem with drawing. but in image viewer example , it doesn't work , it doesn't draw over Label's image.
Moayyad Yaghi
I don't think QLabel is a great foundation to use for a drawing canvas, it's not what they're for. Try using a different widget.
Simon Hibbs
i tried a Qwidget child , but i can't find a good way for the resize (or zoom) . its not flexible in this like the Qlable widget .do u have any better ideas ?
Moayyad Yaghi