使用 PYQT 绘画
我正在尝试在 PYQT 中实现类似 Paint 的程序。我正在尝试使用 PYQT 包中的 Scribble 示例的代码,该代码可以在:C:\Python26\Lib\site-packages\PyQt4\examples\widgets 中找到。现在关于这个我有两个问题:
- 在 Scribble 程序中,绘画时,当您按住鼠标按钮并涂鸦时,绘画不会实时更新。我发现这个问题来自ScribbleArea类中的函数drawLineTo,该行:
self.update(QtCore.QRect(self.lastPoint, endPoint).normalized().adjusted(-rad, -rad, +rad , +rad))
现在,如果我简单地替换这一行,
self.update()
问题就解决了,但光标不在绘画发生的确切位置。
你知道我可以在 self.update() 中添加哪些参数来解决这两个问题吗?
- 我想像 Scribble 一样打开一个图像并在其上绘画,然后仅保存带有空白的绘画,比如说白色背景(背景中没有原始图像)。你能告诉我该怎么做吗?
我将不胜感激您对其中任何一个问题的回答。
谢谢!
I am trying to implement a program like paint in PYQT. I am trying to use the code of Scribble example in PYQT package which can be found in: C:\Python26\Lib\site-packages\PyQt4\examples\widgets. Now regarding this I have 2 questions:
- In the Scribble program, when painting, the paint doesn't get updated visually in real-time as you are holding the mouse button and scribbling. I found out that this problem comes from the function drawLineTo from class ScribbleArea, the line:
self.update(QtCore.QRect(self.lastPoint, endPoint).normalized().adjusted(-rad, -rad, +rad, +rad))
Now if I simply replace this line with
self.update()
the problem is solved, but the cursor is not in the exact location the paintin happens.
Do you know what parameters I can add in the self.update() which solves both problems?
- I want to open an image as Scribble does and paint on it and then save only the paint with a blank lets say white background (without the original image in the back ground). Can you tell me how to do this?
I would appreciate your answer to either of the questions.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
刚刚学习 pyqt,但我修改了代码以解决光标不匹配问题(并修改了 openImage 方法以保持图像大小与窗口同步):
Just learning pyqt, but I modified the code to take care of the cursor mismatch problem (and modified the openImage method to also keep the image size in sync with the window):