QPixmap损坏的imag

2024-03-28 11:39:44 发布

您现在位置:Python中文网/ 问答频道 /正文

为什么我的图像在使用简单的QPixMap和draw命令显示时会损坏。每隔一段时间它就会正确显示。你知道吗

self._pixmap = QtGui.QPixmap(128,128)
painter = QtGui.QPainter(self._pixmap)
brush = QtGui.QBrush(QtCore.Qt.SolidPattern)
brush.setColor(QtGui.QColor(240, 20, 20, 255))
painter.setPen(QtGui.QPen(brush, 1, QtCore.Qt.SolidLine,QtCore.Qt.SquareCap))
painter.drawLine(0, 0, self._pixmap.width(), self._pixmap.height())
painter.drawLine(self._pixmap.width(), 0, 0, self._pixmap.height())
painter.end()

enter image description here


Tags: 图像命令selfqtwidthheightdraw时会
1条回答
网友
1楼 · 发布于 2024-03-28 11:39:44

在使用QPainter绘制之前,应该调用fill,请参阅关于QPixmap构造函数的参考here

This will create a PySide.QtGui.QPixmap with uninitialized data. Call PySide.QtGui.QPixmap.fill() to fill the pixmap with an appropriate color before drawing onto it with PySide.QtGui.QPainter .

相关问题 更多 >