本文整理汇总了Python中PyQt5.Qt.QPen类的典型用法代码示例。如果您正苦于以下问题:Python QPen类的具体用法?Python QPen怎么用?Python QPen使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QPen类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_snake_spinner
def draw_snake_spinner(painter, rect, angle, light, dark):
painter.setRenderHint(QPainter.Antialiasing)
if rect.width() > rect.height():
delta = (rect.width() - rect.height()) // 2
rect = rect.adjusted(delta, 0, -delta, 0)
elif rect.height() > rect.width():
delta = (rect.height() - rect.width()) // 2
rect = rect.adjusted(0, delta, 0, -delta)
disc_width = max(4, rect.width() // 10)
drawing_rect = QRect(rect.x() + disc_width, rect.y() + disc_width, rect.width() - 2 * disc_width, rect.height() - 2 *disc_width)
try:
angle_for_width = math.degrees(math.atan2(1.3 * disc_width, drawing_rect.width()))
except ZeroDivisionError:
angle_for_width = 5
gradient = QConicalGradient(drawing_rect.center(), angle - angle_for_width)
gradient.setColorAt(1, light)
gradient.setColorAt(0, dark)
painter.setPen(QPen(light, disc_width))
painter.drawArc(drawing_rect, 0, 360 * 16)
pen = QPen(QBrush(gradient), disc_width)
pen.setCapStyle(Qt.RoundCap)
painter.setPen(pen)
painter.drawArc(drawing_rect, angle * 16, (360 - 2 * angle_for_width) * 16)
示例2: draw_text
def draw_text(self, style, painter, option, widget, index, item):
tr = style.subElementRect(style.SE_ItemViewItemText, option, widget)
text = index.data(Qt.DisplayRole)
hover = option.state & style.State_MouseOver
if hover or gprefs['tag_browser_show_counts']:
count = unicode_type(index.data(COUNT_ROLE))
width = painter.fontMetrics().boundingRect(count).width()
r = QRect(tr)
r.setRight(r.right() - 1), r.setLeft(r.right() - width - 4)
painter.drawText(r, Qt.AlignCenter | Qt.TextSingleLine, count)
tr.setRight(r.left() - 1)
else:
tr.setRight(tr.right() - 1)
is_rating = item.type == TagTreeItem.TAG and not self.rating_pat.sub('', text)
if is_rating:
painter.setFont(self.rating_font)
flags = Qt.AlignVCenter | Qt.AlignLeft | Qt.TextSingleLine
lr = QRect(tr)
lr.setRight(lr.right() * 2)
br = painter.boundingRect(lr, flags, text)
if br.width() > tr.width():
g = QLinearGradient(tr.topLeft(), tr.topRight())
c = option.palette.color(QPalette.WindowText)
g.setColorAt(0, c), g.setColorAt(0.8, c)
c = QColor(c)
c.setAlpha(0)
g.setColorAt(1, c)
pen = QPen()
pen.setBrush(QBrush(g))
painter.setPen(pen)
painter.drawText(tr, flags, text)
示例3: paintEvent
def paintEvent(self, event):
QWidget.paintEvent(self, event)
pmap = self._pixmap
if pmap.isNull():
return
w, h = pmap.width(), pmap.height()
ow, oh = w, h
cw, ch = self.rect().width(), self.rect().height()
scaled, nw, nh = fit_image(w, h, cw, ch)
if scaled:
pmap = pmap.scaled(int(nw*pmap.devicePixelRatio()), int(nh*pmap.devicePixelRatio()), Qt.IgnoreAspectRatio,
Qt.SmoothTransformation)
w, h = int(pmap.width()/pmap.devicePixelRatio()), int(pmap.height()/pmap.devicePixelRatio())
x = int(abs(cw - w)/2.)
y = int(abs(ch - h)/2.)
target = QRect(x, y, w, h)
p = QPainter(self)
p.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
p.drawPixmap(target, pmap)
if self.draw_border:
pen = QPen()
pen.setWidth(self.BORDER_WIDTH)
p.setPen(pen)
p.drawRect(target)
if self.show_size:
draw_size(p, target, ow, oh)
p.end()
示例4: __call__
def __call__(self, painter, rect, color_theme, title_block, subtitle_block, footer_block):
painter.fillRect(rect, self.color1)
top = title_block.position.y + 2
extra_spacing = subtitle_block.line_spacing // 2 if subtitle_block.line_spacing else title_block.line_spacing // 3
height = title_block.height + subtitle_block.height + extra_spacing + title_block.leading
right = rect.right() - self.hmargin
width = right - self.hmargin
# Draw main banner
p = main = QPainterPath(QPointF(self.hmargin, top))
draw_curved_line(p, rect.width() - 2 * self.hmargin, 0, 0.1, -0.1, 0.9, -0.1)
deltax = self.GRADE * height
p.lineTo(right + deltax, top + height)
right_corner = p.currentPosition()
draw_curved_line(p, - width - 2 * deltax, 0, 0.1, 0.05, 0.9, 0.05)
left_corner = p.currentPosition()
p.closeSubpath()
# Draw fold rectangles
rwidth = self.fold_width
yfrac = 0.1
width23 = int(0.67 * rwidth)
rtop = top + height * yfrac
def draw_fold(x, m=1, corner=left_corner):
ans = p = QPainterPath(QPointF(x, rtop))
draw_curved_line(p, rwidth*m, 0, 0.1, 0.1*m, 0.5, -0.2*m)
fold_upper = p.currentPosition()
p.lineTo(p.currentPosition() + QPointF(-deltax*m, height))
fold_corner = p.currentPosition()
draw_curved_line(p, -rwidth*m, 0, 0.2, -0.1*m, 0.8, -0.1*m)
draw_curved_line(p, deltax*m, -height, 0.2, 0.1*m, 0.8, 0.1*m)
p = inner_fold = QPainterPath(corner)
dp = fold_corner - p.currentPosition()
draw_curved_line(p, dp.x(), dp.y(), 0.5, 0.3*m, 1, 0*m)
p.lineTo(fold_upper), p.closeSubpath()
return ans, inner_fold
left_fold, left_inner = draw_fold(self.hmargin - width23)
right_fold, right_inner = draw_fold(right + width23, m=-1, corner=right_corner)
painter.save()
painter.setRenderHint(QPainter.Antialiasing)
pen = QPen(self.ccolor2)
pen.setWidth(3)
pen.setJoinStyle(Qt.RoundJoin)
painter.setPen(pen)
for r in (left_fold, right_fold):
painter.fillPath(r, QBrush(self.color2))
painter.drawPath(r)
for r in (left_inner, right_inner):
painter.fillPath(r, QBrush(self.color2.darker()))
painter.drawPath(r)
painter.fillPath(main, QBrush(self.color2))
painter.drawPath(main)
painter.restore()
return self.ccolor2, self.ccolor2, self.ccolor1
示例5: __init__
def __init__(self, font_loader, logger, opts, width=0, height=0, parent=None, x=0, y=0):
QGraphicsRectItem.__init__(self, x, y, width, height, parent)
self.font_loader, self.logger, self.opts = font_loader, logger, opts
self.current_y, self.max_y, self.max_x = 0, height, width
self.is_full = False
pen = QPen()
pen.setStyle(Qt.NoPen)
self.setPen(pen)
if not hasattr(self, 'children'):
self.children = self.childItems
示例6: failed_img
def failed_img(self):
if self._failed_img is None:
i = QImage(200, 150, QImage.Format_ARGB32)
i.fill(Qt.white)
p = QPainter(i)
r = i.rect().adjusted(10, 10, -10, -10)
n = QPen(Qt.DashLine)
n.setColor(Qt.black)
p.setPen(n)
p.drawRect(r)
p.setPen(Qt.black)
f = self.font()
f.setPixelSize(20)
p.setFont(f)
p.drawText(r.adjusted(10, 0, -10, 0), Qt.AlignCenter | Qt.TextWordWrap, _('Image could not be rendered'))
p.end()
self._failed_img = QPixmap.fromImage(i)
return self._failed_img
示例7: draw_snake_spinner
def draw_snake_spinner(painter, rect, angle, light, dark):
painter.setRenderHint(QPainter.Antialiasing)
if rect.width() > rect.height():
delta = (rect.width() - rect.height()) // 2
rect = rect.adjusted(delta, 0, -delta, 0)
elif rect.height() > rect.width():
delta = (rect.height() - rect.width()) // 2
rect = rect.adjusted(0, delta, 0, -delta)
disc_width = max(3, min(rect.width() // 10, 8))
drawing_rect = QRect(rect.x() + disc_width, rect.y() + disc_width, rect.width() - 2 * disc_width, rect.height() - 2 *disc_width)
gap = 60 # degrees
gradient = QConicalGradient(drawing_rect.center(), angle - gap // 2)
gradient.setColorAt((360 - gap//2)/360.0, light)
gradient.setColorAt(0, dark)
pen = QPen(QBrush(gradient), disc_width)
pen.setCapStyle(Qt.RoundCap)
painter.setPen(pen)
painter.drawArc(drawing_rect, angle * 16, (360 - gap) * 16)
示例8: paint
def paint (self,painter,option, widget):
painter.setRenderHints(QtGui.QPainter.Antialiasing)
painter.rotate(self.rotation)
painter.translate(-self.size/2,-self.size/2)
#painter.scale(300,600)
#c = self.model.groupe_color_value[self.heros.groupe().attribs['color']]
pen = QPen(QtCore.Qt.black)
if self.isSelected() == True :
pen.setWidth(2)
else:
pen.setWidth(1)
painter.setPen(pen)
radialGradient = QRadialGradient(self.size/2, self.size/2,self.size*0.8, self.size, self.size)
radialGradient.setColorAt(0.0, QtCore.Qt.white)
#radialGradient.setColorAt(0.2, self.heros.kingdom().color)
if self.view.color_mode == ColorMode.Empire :
color = self.heros.empire().color
elif self.view.color_mode == ColorMode.Kingdom :
color = self.heros.kingdom().color
else:
color = self.model.groupe_color_value[self.heros.groupe().attribs['color']]
radialGradient.setColorAt(0.2, color)
radialGradient.setColorAt(1.0, QtCore.Qt.black)
painter.setBrush(QBrush(radialGradient))
if self.heros.faction().name == "Lumiere":
painter.drawEllipse(0,0,self.size,self.size)
else:
poly = self.getTriangle(self.Size)
painter.drawPolygone(poly)
if self.name_visible == True :
painter.setPen(QPen(QColor('black')))
painter.translate(0,10)
self.ratio = 1.2
rect = QRectF(0,0,self.size,self.size*self.ratio)
painter.drawText (rect,QtCore.Qt.AlignHCenter|QtCore.Qt.AlignBottom, self.name)
示例9: paintEvent
def paintEvent(self, event):
QWidget.paintEvent(self, event)
pmap = self._pixmap
if pmap.isNull():
return
w, h = pmap.width(), pmap.height()
ow, oh = w, h
cw, ch = self.rect().width(), self.rect().height()
scaled, nw, nh = fit_image(w, h, cw, ch)
if scaled:
pmap = pmap.scaled(int(nw*pmap.devicePixelRatio()), int(nh*pmap.devicePixelRatio()), Qt.IgnoreAspectRatio,
Qt.SmoothTransformation)
w, h = int(pmap.width()/pmap.devicePixelRatio()), int(pmap.height()/pmap.devicePixelRatio())
x = int(abs(cw - w)/2.)
y = int(abs(ch - h)/2.)
target = QRect(x, y, w, h)
p = QPainter(self)
p.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
p.drawPixmap(target, pmap)
if self.draw_border:
pen = QPen()
pen.setWidth(self.BORDER_WIDTH)
p.setPen(pen)
p.drawRect(target)
if self.show_size:
sztgt = target.adjusted(0, 0, 0, -4)
f = p.font()
f.setBold(True)
p.setFont(f)
sz = u'\u00a0%d x %d\u00a0'%(ow, oh)
flags = Qt.AlignBottom|Qt.AlignRight|Qt.TextSingleLine
szrect = p.boundingRect(sztgt, flags, sz)
p.fillRect(szrect.adjusted(0, 0, 0, 4), QColor(0, 0, 0, 200))
p.setPen(QPen(QColor(255,255,255)))
p.drawText(sztgt, flags, sz)
p.end()
示例10: paint
def paint(self, painter, option, widget):
pen = QPen(Qt.red)
pen.setWidth(2)
painter.setPen(pen)
painter.drawRoundedRect(1, 1, self._width - 3, self._height - 3, 5, 5)