【发布时间】:2017-08-03 19:21:53
【问题描述】:
我是 PyQt5 的新手,我找不到任何对我有用的关于如何在加载的图像 (QPixmap("myPic.png")) 上使用 QPainter 绘制的答案。我尝试在paintEvent 方法中执行此操作,但没有成功。如果我想在下面的 sn-p 中加载的图像上画一条线,我该怎么做呢?
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
class Example(QWidget):
def __init__(self):
super().__init__()
self.setGeometry(30, 30, 500, 300)
self.initUI()
def initUI(self):
self.pixmap = QPixmap("myPic.png")
lbl = QLabel(self)
lbl.setPixmap(self.pixmap)
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
【问题讨论】:
-
您想用水平线显示图像,还是想保存更改后的图像?
-
第一个。在图像顶部显示线条,如 qpainter.drawLine()
标签: python pyqt pyqt5 qpixmap qlabel