扩展pyqt或QT的图像查看器示例

发布于 2024-09-09 05:08:28 字数 500 浏览 3 评论 0原文

我正在尝试扩展 pyqt image veiwer 示例以具有在图像上绘图的功能
我添加了几个经过测试的函数,它们接受鼠标事件并在图像上绘制
在图像查看器示例中,我选择了画家在 imageLabel 的 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())

。 。 。

问题是:它根本没有在像素图上绘制..它显示图像,缩放,可以执行所有操作,但绘图不起作用..我做错了什么吗?我已经尝试了三天但没有结果。有人有更好的主意吗?
提前致谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

红焚 2024-09-16 05:08:28

首先捕获鼠标事件并使用 print 语句显示结果,以确保您正确获取鼠标数据。下一步是使用鼠标数据和鼠标事件将其输入到绘图例程中。

虽然它不包括获取鼠标输入,但这个 有关在 PyQt 中绘图的教程 应该会向您指出就使用 API 创建绘图而言,方向正确。尝试命令式绘图,即不基于鼠标输入,并检查其显示是否正确。

最后,您应该能够将两者结合在一起,使用鼠标事件和数据来驱动绘图例程。

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.

听不够的曲调 2024-09-16 05:08:28

我不知道这是否有帮助,但我已经设法使用 QLabel 和 QImage 使选择框显示一个小部件。基本上每次我对 QImage 进行更改时,我都必须将其重新设置为标签的图像:

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

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 ) )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文