本文整理汇总了Python中PySide.QtGui.QPainter类的典型用法代码示例。如果您正苦于以下问题:Python QPainter类的具体用法?Python QPainter怎么用?Python QPainter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QPainter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paintEvent
def paintEvent(self, painteevent):
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing)
for obj in self.objects:
obj.paint(painter)
示例2: paintEvent
def paintEvent(self, e):
'Custom Paint Event'
p = QPainter(self)
opt = QStyleOptionFrameV3()
opt.initFrom(self)
opt.rect = self.contentsRect()
opt.lineWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth, opt, self)
opt.midLineWidth = 0
opt.state = opt.state | QStyle.State_Sunken
if self._active:
opt.state = opt.state | QStyle.State_HasFocus
else:
opt.state = opt.state & ~QStyle.State_HasFocus;
self.style().drawPrimitive(QStyle.PE_PanelLineEdit, opt, p)
y = (opt.rect.height() - self._star.height()) / 2
width = self._star.width()
for i in range(0, 5):
x = i*(width + 1) + opt.lineWidth
if self._rating >= i+0.5:
p.drawImage(x, y, self._star if not self._active else self._blue)
else:
p.drawImage(x, y, self._dot)
示例3: set_clipboard_image
def set_clipboard_image(self):
"""Export the formatted output to an image and store it in the
clipboard.
The image stored in the clipboard is a PNG file with alpha
transparency.
"""
div = self.view.page().mainFrame().findFirstElement('.output')
images = {}
for background in (Qt.transparent, Qt.white):
image = QImage(div.geometry().size(),
QImage.Format_ARGB32_Premultiplied)
image.fill(background)
painter = QPainter(image)
div.render(painter)
painter.end()
images[background] = image
# Windows needs this buffer hack to get alpha transparency in
# the copied PNG.
buffer_ = QBuffer()
buffer_.open(QIODevice.WriteOnly)
images[Qt.transparent].save(buffer_, 'PNG')
buffer_.close()
data = QMimeData()
data.setData('PNG', buffer_.data())
data.setImageData(images[Qt.white])
QApplication.clipboard().setMimeData(data)
示例4: paintEvent
def paintEvent(self, pe):
painter = QPainter(self)
if self._fill:
scaled_pixmap = self._image_pixmap.scaled(self.size(), Qt.IgnoreAspectRatio)
painter.drawPixmap(0, 0, scaled_pixmap)
else:
painter.drawPixmap(0, 0, self._image_pixmap)
示例5: SetImageTransparency
def SetImageTransparency(image, transparencyPercentage):
""" Set the Image Transparency to the value provided """
alpha = QImage(image)
painter = QPainter(alpha)
alphaValue = int(transparencyPercentage*255/100)
painter.fillRect(alpha.rect(), QColor(alphaValue, alphaValue, alphaValue))
painter.end()
image.setAlphaChannel(alpha)
示例6: paint
def paint(self, painter, option, widget=None):
painter_inverted = QPainter()
brect= QGraphicsProxyWidget.boundingRect(self)
invertedColor = QImage(brect.width(),brect.height(),QImage.Format_RGB32)
painter_inverted.begin(invertedColor)
QGraphicsProxyWidget.paint(self,painter_inverted, option, widget)
painter_inverted.end()
painter.drawImage(0,0,invertedColor.rgbSwapped())
示例7: resizeImage
def resizeImage(self, image, newSize):
if image.size() == newSize:
return
newImage = QImage(newSize, QImage.Format_RGB32)
newImage.fill(qRgb(255, 255, 255))
painter = QPainter(newImage)
painter.drawImage(QtCore.QPoint(0, 0), image)
self.image = newImage
示例8: _update_cursor
def _update_cursor(self):
x = self.diameter
w, h = x, x
pixmap = QPixmap(w, h)
pixmap.fill(Qt.transparent)
p = QPainter(pixmap)
p.drawPoints(self._points)
p.end()
self._cursor_pixmap = pixmap.createMaskFromColor(Qt.transparent)
示例9: paintEvent
def paintEvent(self, pe):
if self._mouse_over:
icon = self._hover_icon
else:
icon = self._normal_icon
painter = QPainter(self)
pixmap = QPixmap(icon)
pixmap = pixmap.scaled(self.size(), Qt.IgnoreAspectRatio)
painter.drawPixmap(0, 0, pixmap)
示例10: capture
def capture(self, filename):
image = QImage(self._view.page().currentFrame().contentsSize(), QImage.Format_ARGB32)
painter = QPainter(image)
self._view.page().currentFrame().render(painter)
painter.end()
image.save(filename)
示例11: paintEvent
def paintEvent(self, event):
painter = QPainter()
painter.begin(self)
self.theme.render(painter, "kdiamond-" + self.color)
if self.selected:
self.theme.render(painter, "kdiamond-selection")
painter.end()
示例12: paintEvent
def paintEvent(self, pe):
super(ProgressLineEdit, self).paintEvent(pe)
painter = QPainter(self)
painter.setOpacity(self.property("_progress_opacity"))
sopb = QStyleOptionProgressBarV2()
sopb.minimum = 0
sopb.maximum = 100
sopb.progress = self._progress
sopb.initFrom(self)
self.style().drawControl(QStyle.CE_ProgressBarContents, sopb, painter, self)
示例13: paintEvent
def paintEvent(self, event):
"""
Handles the ``paintEvent`` event for :class:`ImageWidget`.
:param `event`: A `QPaintEvent`_ to be processed.
"""
painter = QPainter(self)
painter.drawPixmap(0, 0, self.pixmap)
if self.parent.lightswitch.isOn: # Turn the light on.
painter.drawImage(self.size().width() - 113, 1, self.lightOnImg)
示例14: paint
def paint(self, canvas, is_secondary_color=False, additional_flag=False):
pen = QPen()
pen.setWidth(self.data_singleton.pen_size)
pen.setStyle(Qt.SolidLine)
pen.setCapStyle(Qt.RoundCap)
pen.setJoinStyle(Qt.RoundJoin)
if is_secondary_color:
pen.setBrush(self.data_singleton.secondary_color)
else:
pen.setBrush(self.data_singleton.primary_color)
painter = QPainter(canvas.image)
painter.setPen(pen)
if self._start_point != self._end_point:
painter.drawLine(self._start_point, self._end_point)
if self._start_point == self._end_point:
painter.drawPoint(self._start_point)
painter.end()
canvas.edited = True
canvas.update()
示例15: paintEvent
def paintEvent(self, e):
''' overwrite paintEvent in order to also redraw points (indicating
electrode positions) and their link to added plots
this is necessary to get smooth animation if plots are dragged around
'''
super(DragWindow, self).paintEvent(e)
qp = QPainter()
qp.begin(self)
self.drawPoints(qp)
qp.end()