本文整理汇总了Python中PySide.QtGui.QPainter.setPen方法的典型用法代码示例。如果您正苦于以下问题:Python QPainter.setPen方法的具体用法?Python QPainter.setPen怎么用?Python QPainter.setPen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QPainter
的用法示例。
在下文中一共展示了QPainter.setPen方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setPen [as 别名]
def paintEvent(self, pe):
if not self._hover_rect:
super(TrackerWebView, self).paintEvent(pe)
else:
super(TrackerWebView, self).paintEvent(pe)
hover_rect = self._hover_rect
self._fixRectForScroll(hover_rect)
painter = QPainter(self)
painter.save()
pen = QPen(Qt.red)
pen.setWidth(2)
painter.setPen(pen)
painter.drawRect(hover_rect)
painter.restore()
# draw green rects around the similar elements
pen = QPen()
pen.setWidth(2)
for field_info in self._fields_info:
painter.save()
web_elements = field_info.web_elements
color = field_info.color
pen.setColor(color)
painter.setPen(pen)
for elem in web_elements:
elem_rect = elem.absoluteGeometry()
painter.drawRoundedRect(self._fixRectForScroll(elem_rect), 2, 2)
painter.restore()
示例2: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setPen [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)
示例3: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setPen [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: paint
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setPen [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()
示例5: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setPen [as 别名]
def paintEvent(self, event):
""" Paints the widgets:
- paints the background
- paint each visible blocks that intersects the widget bbox.
"""
painter = QPainter(self)
painter.fillRect(event.rect(), self.back_brush)
painter.setPen(self.text_pen)
painter.setFont(self.font)
w = self.width() - 2
# better name lookup speed
painter_drawText = painter.drawText
align_right = Qt.AlignRight
normal_font = painter.font()
normal_font.setBold(False)
bold_font = QFont(normal_font)
bold_font.setBold(True)
active = self.editor.codeEdit.textCursor().blockNumber()
for vb in self.editor.codeEdit.visible_blocks:
row = vb.row
if row == active + 1:
painter.setFont(bold_font)
else:
painter.setFont(normal_font)
painter_drawText(0, vb.top, w, vb.height, align_right,
str(row))
return Panel.paintEvent(self, event)
示例6: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setPen [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)
示例7: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setPen [as 别名]
def paintEvent(self, event):
text = []
text.append(['{0}; {1}'.format(self.parent.chunkData['X'], self.parent.chunkData['Y']), Qt.black])
if self.parent.chunkData[14] > 0:
text.append(['Gold = {0}'.format(self.parent.chunkData[14]), Qt.yellow])
else:
text.append(['', Qt.yellow])
if self.parent.chunkData[15] > 0:
text.append(['Iron = {0}'.format(self.parent.chunkData[15]), Qt.red])
else:
text.append(['', Qt.red])
if self.parent.chunkData[56] > 0:
text.append(['Diamond = {0}'.format(self.parent.chunkData[56]), Qt.cyan])
else:
text.append(['', Qt.cyan])
if self.parent.chunkData[73] > 0:
text.append(['Redstone = {0}'.format(self.parent.chunkData[73]), Qt.magenta])
else:
text.append(['', Qt.magenta])
if self.parent.chunkData[49] > 0:
text.append(['Obsidian = {0}'.format(self.parent.chunkData[49]), Qt.darkYellow])
else:
text.append(['', Qt.darkYellow])
if self.parent.chunkData[21] > 0:
text.append(['Lazurit = {0}'.format(self.parent.chunkData[21]), Qt.darkBlue])
else:
text.append(['', Qt.darkBlue])
painter = QPainter()
painter.begin(self)
painter.drawRect(self.parent.leftMargin, self.parent.topMargin,
self.edgeLen, self.edgeLen)
cX = self.parent.leftMargin + self.parent.vsepara
cY = self.parent.topMargin + self.parent.hsepara
alig = Qt.AlignCenter
i = 0
fontik = painter.font()
for t in text:
if i > 0:
alig = Qt.AlignLeft
painter.setPen(t[1])
if i == 2:
fontik.setUnderline(True)
else:
fontik.setUnderline(False)
painter.setFont(fontik)
painter.drawText(cX, cY, self.tBoxWidth, self.tBoxHeight, alig, t[0])
cY += self.lineSpacing
i += 1
painter.end()
del painter
示例8: draw
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setPen [as 别名]
def draw(self, endPoint_x, endPoint_y):
painter = QPainter(self.image)
painter.setPen(QPen(
self.myPenColor, self.myPenWidth, QtCore.Qt.SolidLine,
QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin))
painter.setClipping(True)
painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
painter.setRenderHint(QPainter.HighQualityAntialiasing, True)
painter.setRenderHint(QPainter.Antialiasing, True)
painter.setCompositionMode(QPainter.CompositionMode())
if self.tools['circle']:
x1 = self.firstPoint_x
y1 = self.firstPoint_y
x2 = endPoint_x
y2 = endPoint_y
painter.drawEllipse(x1, y1, (x2 - x1), (y2 - y1))
if self.tools['eraser']:
painter.setPen(QPen(QtCore.Qt.white, 10, QtCore.Qt.SolidLine))
painter.drawLine(
self.firstPoint_x, self.firstPoint_y, endPoint_x, endPoint_y)
self.firstPoint_x = endPoint_x
self.firstPoint_y = endPoint_y
if self.tools['pen']:
painter.drawLine(
self.firstPoint_x, self.firstPoint_y, endPoint_x, endPoint_y)
self.firstPoint_x = endPoint_x
self.firstPoint_y = endPoint_y
if self.tools['line'] and self.flag:
painter.drawLine(
self.firstPoint_x, self.firstPoint_y, endPoint_x, endPoint_y)
if self.tools['rect']:
dx = endPoint_x - self.firstPoint_x
dy = endPoint_y - self.firstPoint_y
painter.drawRect(self.firstPoint_x, self.firstPoint_y, dx, dy)
if self.tools['roundRect']:
x1 = self.firstPoint_x
y1 = self.firstPoint_y
dx = endPoint_x - self.firstPoint_x
dy = endPoint_y - self.firstPoint_y
if x1 > endPoint_x and y1 > endPoint_y:
painter.drawRoundedRect(
endPoint_x, endPoint_y, -dx, -dy, 20, 20, 0)
else:
painter.drawRoundedRect(x1, y1, dx, dy, 20., 20.)
self.modified = True
self.update()
示例9: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setPen [as 别名]
def paintEvent(self, event):
"""
Handles the ``paintEvent`` event for :class:`SelectBox`.
:param `event`: A `QPaintEvent`_ to be processed.
"""
painter = QPainter(self)
painter.setPen(self._dirPen)
width, height = self.width(), self.height()
painter.fillRect(0, 0, width - 1, height - 1, self._dirBrush)
painter.drawRect(0, 0, width - 1, height - 1)
示例10: draw_marker
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setPen [as 别名]
def draw_marker(self, x, y, pixmap, scale):
"Draw the brush marker indicating what area will be painted"
w, h = self.size*scale, self.size*scale
painter = QPainter(pixmap)
painter.setPen(Qt.green)
painter.drawRect(x - w/2, y - h/2, w, h)
x = pixmap.width() - x
y = pixmap.height() - y
painter.drawRect(x - w/2, y - h/2, w, h)
示例11: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setPen [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()
示例12: __paintMargin
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setPen [as 别名]
def __paintMargin(self, event):
""" Paints the right margin as postPainting step. """
rect = event.rect()
font = self.editor.codeEdit.currentCharFormat().font()
fm = QFontMetricsF(font)
pos = self.marginPos
offset = self.editor.codeEdit.contentOffset().x() + \
self.editor.codeEdit.document().documentMargin()
x80 = round(fm.width(' ') * pos) + offset
p = QPainter(self.editor.codeEdit.viewport())
p.setPen(self.pen)
p.drawLine(x80, rect.top(), x80, rect.bottom())
示例13: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setPen [as 别名]
def paintEvent(self, ev):
if not self._osx:
return
size = self.size()
height = size.height()-1
width = size.width()-1
painter = QPainter(self)
painter.setPen(QColor(165, 165, 165, 255))
painter.drawLine(QPoint(0, 0), QPoint(0, height))
painter.drawLine(QPoint(0, height), QPoint(width, height))
painter.drawLine(QPoint(width, height), QPoint(width, 0))
for index in range(self._buttonCount):
xCoord = (index + 1) * 21 - 1
painter.drawLine(QPoint(xCoord, 0), QPoint(xCoord, height))
示例14: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setPen [as 别名]
def paintEvent(self, event):
""" Paints the widget """
if self.enabled is False:
return
Panel.paintEvent(self, event)
painter = QPainter(self)
painter.fillRect(event.rect(), self.back_brush)
for vb in self.editor.codeEdit.visible_blocks:
line = vb.row
# paint marker for line
marker = self.getIndicatorForLine(line)
if marker is None:
continue
# use the normal pen to draw the fold indicator
drawLines = False
pen = self.normal_pen
if marker.hover is True:
pen = self.highlight_pen
drawLines = True
painter.setPen(pen)
# get the text to draw
txt = '-'
if marker.folded is True:
drawLines = False
txt = '+'
offset = 4
h = self.size_hint.height()
fm = QFontMetricsF(self.editor.codeEdit.font())
hoffset = (fm.height() - h) / 2.0
r = QRect(vb.rect.x(), vb.rect.y() + hoffset, self.size_hint.width(), self.size_hint.height())
painter.setFont(self.font)
painter.drawText(r, Qt.AlignVCenter | Qt.AlignHCenter, txt)
w = self.size_hint.width() - 2 * offset
h = self.size_hint.width() - 2 * offset
hoffset = (fm.height() - h) / 2.0
r.setX(vb.rect.x() + offset)
r.setY(vb.rect.y() + hoffset)
r.setWidth(w)
r.setHeight(h)
painter.drawRect(r)
if drawLines is True:
top = (vb.rect.x() + self.size_hint.width() / 2.0,
vb.rect.y() + hoffset + offset * 2)
delta = ((marker.end - marker.start) * vb.height) # - (vb.rect.height() / 2.0)
bottom = (top[0], top[1] + delta)
painter.drawLine(top[0], top[1], bottom[0], bottom[1])
painter.drawLine(bottom[0], bottom[1], bottom[0] + self.size_hint.width() / 2.0, bottom[1])
return
示例15: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setPen [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)