Moayyad Yaghi
Moayyad Yaghi

Reputation: 3732

expanding the image viewer example of pyqt or QT

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

Upvotes: 2

Views: 2689

Answers (2)

Jay
Jay

Reputation: 3489

I dunno if this is gonna help but I've managed to make a selection box show up an a widget using QLabel and QImage. Basically every time I made a change to the QImage I had to re-set it as the label's image:

self.imgLabel.setPixmap( QPixmap.fromImage( self.image ) )

Upvotes: 0

Simon Hibbs
Simon Hibbs

Reputation: 6221

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.

Upvotes: 1

Related Questions