本文整理汇总了Python中PySide.QtGui.QPainter.setBrush方法的典型用法代码示例。如果您正苦于以下问题:Python QPainter.setBrush方法的具体用法?Python QPainter.setBrush怎么用?Python QPainter.setBrush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QPainter
的用法示例。
在下文中一共展示了QPainter.setBrush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setBrush [as 别名]
def paintEvent(self, ev):
if self.isEnabled():
color = self.color
colorBorder = [0.4, 0.4, 0.4]
else:
color = [0.8, 0.8, 0.8]
colorBorder = [0.7, 0.7, 0.7]
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing)
painter.setRenderHint(QPainter.HighQualityAntialiasing)
if self.isChecked():
pen = QPen(QColor.fromRgbF(0.2, 0.2, 0.2))
pen.setWidth(2.0)
else:
pen = QPen(QColor.fromRgbF(colorBorder[0], colorBorder[1], colorBorder[2]))
pen.setWidth(1.0)
size = self.size()
sizeCircle = 12.0
x = size.width() / 2.0 - (sizeCircle / 2.0)
y = size.height() / 2.0 - (sizeCircle / 2.0)
rect = QRectF(x, y, sizeCircle, sizeCircle)
painter.setPen(pen)
painter.setBrush(QColor.fromRgbF(color[0], color[1], color[2]))
painter.drawEllipse(rect)
示例2: paint
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setBrush [as 别名]
def paint(self, canvas, is_secondary_color=False, additional_flag=False):
pen = QPen()
if is_secondary_color:
pen.setColor(self.data_singleton.secondary_color)
else:
pen.setColor(self.data_singleton.primary_color)
painter = QPainter(canvas.image)
painter.setRenderHint(QPainter.Antialiasing)
pen.setWidth(self.data_singleton.pen_size)
pen.setStyle(Qt.SolidLine)
pen.setCapStyle(Qt.RoundCap)
pen.setJoinStyle(Qt.RoundJoin)
painter.setPen(pen)
if is_secondary_color:
painter.setBrush(self.data_singleton.primary_color)
else:
painter.setBrush(self.data_singleton.secondary_color)
if self._start_point != self._end_point:
painter.drawRect(QRect(self._start_point, self._end_point))
painter.end()
canvas.edited = True
canvas.update()
示例3: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setBrush [as 别名]
def paintEvent(self, pe):
# make an arrow polygon right in the middle
painter = QPainter(self)
painter.setPen(Qt.NoPen)
# draw the background transparent rect
painter.save()
painter.setOpacity(self.BACKGROUND_OPACITY)
# get the rectangle coordinates it should extend over the whole width with only a portion at the center
painter.setBrush(Qt.black)
empty_space_percent = 1 - self.BACKROUND_HEIGHT_PERCENT
rect_top = empty_space_percent / 2 * self.height()
rect_height = self.BACKROUND_HEIGHT_PERCENT * self.height()
painter.drawRect(0, rect_top, self.width(), rect_height)
painter.restore()
painter.setRenderHint(QPainter.Antialiasing)
pen = QPen()
pen.setWidth(self.ARROW_LINE_WIDTH)
pen.setCapStyle(Qt.RoundCap)
if self._mouse_inside:
pen.setColor(self._hover_color)
else:
pen.setColor(self._normal_color)
# get the arrow coords
painter.setPen(pen)
self_center = QPointF(self.width() / 2, self.height() / 2) # use this as the arrow tip for now
if self._direction == self.LEFT:
h_shift = self._arrow_width
elif self._direction == self.RIGHT:
h_shift = - self._arrow_width
v_shift = self._arrow_height / 2
top_point = self_center + QPointF(h_shift, - v_shift)
bottom_point = self_center + QPointF(h_shift, v_shift)
painter.drawLine(top_point, self_center)
painter.drawLine(self_center, bottom_point)
示例4: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setBrush [as 别名]
def paintEvent(self, pe):
painter = QPainter(self)
painter.save()
gradient = QLinearGradient()
gradient.setStart(self._grad_start)
gradient.setFinalStop(self._grad_end)
gradient.setColorAt(0, QColor(230, 230, 230))
gradient.setColorAt(1, QColor(247, 247, 247))
brush = QBrush(gradient)
painter.setBrush(brush)
pen = QPen(Qt.black)
pen.setWidth(1)
painter.setPen(pen)
painter.drawPath(self._painter_path)
painter.restore()
font = QFont()
font.setFamily("Tahoma")
font.setPixelSize(11)
font.setBold(True)
pen = QPen(Qt.darkGray)
painter.setPen(pen)
painter.setFont(font)
self_rect = QRect(self.rect())
self_rect.moveTo(self._hor_margin, self._ver_margin // 2)
painter.drawText(self_rect, Qt.AlignLeft, self._text)
示例5: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setBrush [as 别名]
def paintEvent(self, event):
paintRegion = event.region()
painter = QPainter(self)
pal = self.palette()
for shape in self._shapeList:
rect = shape.rect
if not paintRegion.contains(rect):
continue
shapeType = shape.type
painter.setBrush(shape.color)
if shapeType == ShapeType.Rectangle:
print "rectangle"
painter.drawRect(rect)
elif shapeType == ShapeType.Circle:
print "circle"
painter.drawEllipse(rect)
# paint the shape name
painter.setBrush(pal.text())
painter.drawText(rect, Qt.AlignCenter, shape.name)
示例6: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setBrush [as 别名]
def paintEvent(self, event):
painter = QPainter()
painter.begin(self)
painter.setRenderHint(QPainter.HighQualityAntialiasing)
painter.setRenderHint(QPainter.Antialiasing)
painter.setRenderHint(QPainter.SmoothPixmapTransform)
painter.setBrush(QColor(self.color))
painter.drawRect(self.window().x() + 4, self.window().y() + 4, self.window().width(), self._height)
painter.end()
示例7: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setBrush [as 别名]
def paintEvent(self, evt):
# print 'paint', self.color, self.text(), self.width(), self.height(), evt.rect().width()
qp = QPainter()
qp.begin(self)
qp.setBrush(QColor('#{}'.format(self.color[:-2])))
qp.drawRect(0, 0, self.width(), self.height())
qp.end()
qp.begin(self)
qp.setPen(self._get_text_color())
qp.drawText(evt.rect(), QtCore.Qt.AlignCenter, self.text())
qp.end()
示例8: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setBrush [as 别名]
def paintEvent(self, event):
painter = QPainter(self)
painter.setBrush(Qt.white)
painter.drawRect(self.rect())
painter.translate(self.width()/2, self.height()/2)
if self.pixReady:
grammarPix = QPixmap("/tmp/grammar.png")
pw = grammarPix.width()
ph = grammarPix.height()
painter.drawPixmap(-pw/2, -ph/2, grammarPix)
示例9: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setBrush [as 别名]
def paintEvent(self,e):
painter = QPainter(self)
for rect in self.rectangles:
try:
xa,ya,xb,yb = rect
rect = xa,ya,xb-xa,yb-ya
painter.setBrush(randomColor())
painter.drawRect(QRect(*rect))
except:
print('rect was foul')
示例10: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setBrush [as 别名]
def paintEvent(self, ev):
size = self.size()
height = size.height() - 5
width = size.width() - 5
offset = 0.5
rect = QRectF(2.0 + offset, 2.0 + offset, width, height)
painter = QPainter(self)
painter.setPen(self._pen)
painter.setBrush(QColor(self._color[0], self._color[1], self._color[2]))
painter.setRenderHint(QPainter.Antialiasing)
painter.setRenderHint(QPainter.HighQualityAntialiasing)
painter.drawRoundedRect(rect, 4, 4)
示例11: svg2icon
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setBrush [as 别名]
def svg2icon(path, img_type=QImage):
img = QImage(64, 64, QImage.Format_ARGB32)
svgrenderer = QSvgRenderer(path)
paint = QPainter(img)
paint.setRenderHint(QPainter.HighQualityAntialiasing)
paint.setRenderHint(QPainter.SmoothPixmapTransform)
paint.setBrush(QColor(255, 255, 255, 255))
paint.drawRect(QRect(-1, -1, 65, 65))
svgrenderer.render(paint)
paint.end()
if img_type == QImage:
return img
elif img_type == QPixmap:
pix = QPixmap
pix = pix.fromImage(img)
return pix
示例12: createPixmap
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setBrush [as 别名]
def createPixmap(self):
"""Creates the pixmap shown when this label is dragged."""
font_metric = QFontMetrics(QFont())
text_size = font_metric.size(Qt.TextSingleLine, self.text)
image = QImage(text_size.width() + 4, text_size.height() + 4,
QImage.Format_ARGB32_Premultiplied)
image.fill(qRgba(240, 240, 120, 255))
painter = QPainter()
painter.begin(image)
painter.setFont(QFont())
painter.setBrush(Qt.black)
painter.drawText(QRect(QPoint(2, 2), text_size), Qt.AlignCenter,
self.text)
painter.end()
return image
示例13: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setBrush [as 别名]
def paintEvent(self, event):
"""
This function handles the low level painting of component.
:param event:
:return:
"""
painter = QPainter()
painter.begin(self)
painter.setRenderHint(QPainter.Antialiasing)
if self.__flag == 1:
painter.end()
return
# setting the masking ellipse
painter.setClipRegion(self.__clip)
self.__color.setAlpha(self.__maxOpacity)
painter.setBrush(QBrush(self.__color))
painter.setPen(QPen(QColor(0, 0, 0, 0)))
painter.drawEllipse(self.__origin, self.__r, self.__r)
painter.end()
示例14: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setBrush [as 别名]
def paintEvent(self, event):
mouse_pos = self.mapFromGlobal(QCursor.pos())
is_hover = self.contentsRect().contains(mouse_pos)
if not self.new_ui:
QPushButton.paintEvent(self, event)
painter = QPainter(self)
if self.new_ui and self.isChecked():
painter.setRenderHint(QPainter.Antialiasing)
painter.setPen(QPen(Qt.NoPen))
painter.setBrush(self.highlight)
painter.drawRoundedRect(event.rect(), 2, 2)
painter.drawPixmap(2, 2, self.icon)
if is_hover:
painter.setCompositionMode(QPainter.CompositionMode_Screen)
painter.drawPixmap(2, 2, self.icon)
示例15: createPixmapIcon
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setBrush [as 别名]
def createPixmapIcon(self):
self.markerIcon = QPixmap(MARKER_WIDTH, MARKER_HEIGHT)
self.markerIcon.fill(Qt.transparent)
painter = QPainter(self.markerIcon)
p1 = QPoint(MARKER_WIDTH / 2, MARKER_HEIGHT - 1)
p2 = QPoint(MARKER_WIDTH / 2, MARKER_HEIGHT - 1 - MARKER_PIN_LEN)
pen = QPen(Qt.black)
pen.setWidth(2)
pen.setCosmetic(True)
painter.setPen(pen)
painter.drawLine(p1, p2)
ellipse = QRect(0, 0, MARKER_WIDTH - 1, MARKER_HEIGHT - 1)
pen.setWidth(1)
painter.setPen(pen)
color = QColor(Qt.green)
color.setAlpha(127)
brush = QBrush(color)
painter.setBrush(brush)
painter.drawEllipse(ellipse)