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 pixmapdef mousMoveEvent(self,event): painter = QtGui.QPainter(self.imageLabel.pixmap()) painter.setPen(QtGui.QPen (self.chosenColor,self.chosenWidt开发者_如何学Goh,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 advanceStart 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.
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 ) )
精彩评论