本文整理汇总了Python中PySide.QtGui.QPainter.setFont方法的典型用法代码示例。如果您正苦于以下问题:Python QPainter.setFont方法的具体用法?Python QPainter.setFont怎么用?Python QPainter.setFont使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QPainter
的用法示例。
在下文中一共展示了QPainter.setFont方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setFont [as 别名]
def paintEvent(self, event):
contents_y = self.edit.verticalScrollBar().value()
page_bottom = contents_y + self.edit.viewport().height()
font_metrics = self.fontMetrics()
current_block = self.edit.document().findBlock(self.edit.textCursor().position())
painter = QPainter(self)
line_count = 0
block = self.edit.document().begin()
while block.isValid():
line_count += 1
position = self.edit.document().documentLayout().blockBoundingRect(block).topLeft()
if position.y() > page_bottom:
break
bold = False
if block == current_block:
bold = True
font = painter.font()
font.setBold(True)
painter.setFont(font)
self.current = line_count
painter.drawText(
self.width() - font_metrics.width(str(line_count)) - 10,
round(position.y()) - contents_y + font_metrics.ascent(),
str(line_count),
)
if bold:
font = painter.font()
font.setBold(False)
painter.setFont(font)
block = block.next()
self.highest_line = line_count
painter.end()
QWidget.paintEvent(self, event)
示例2: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setFont [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 setFont [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
示例4: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setFont [as 别名]
def paintEvent(self, event):
QPushButton.paintEvent(self, event)
qp = QPainter()
qp.begin(self)
font = qp.font()
font.setPixelSize(8)
font.setWeight(QFont.Normal)
qp.setFont(font)
qp.drawText(event.rect().translated(1, 1), str(self._atomic_number))
qp.end()
示例5: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setFont [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
示例6: createPixmap
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setFont [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
示例7: _numberbar_paint
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setFont [as 别名]
def _numberbar_paint(self, number_bar, event):
'''Paint number bar.'''
font_metrics = self.fontMetrics()
current_line = self.edit.document().findBlock(
self.edit.textCursor().position()
).blockNumber() + 1
block = self.edit.firstVisibleBlock()
line_count = block.blockNumber()
painter = QPainter(number_bar)
painter.fillRect(event.rect(), self.palette().base())
# Iterate over all visible text blocks in the document.
while block.isValid():
line_count += 1
block_top = self.edit.blockBoundingGeometry(block).\
translated(self.edit.contentOffset()).top()
# Check if the position of the block is out side of the visible
# area.
if not block.isVisible() or block_top >= event.rect().bottom():
break
# We want the line number for the selected line to be bold.
if line_count == current_line:
font = painter.font()
font.setBold(True)
font.setUnderline(True)
painter.setFont(font)
else:
font = painter.font()
font.setBold(False)
font.setUnderline(False)
painter.setFont(font)
# Draw the line number right justified at the position of the
# line.
paint_rect = QRect(0, block_top, number_bar.width(),
font_metrics.height())
painter.drawText(paint_rect, Qt.AlignRight,
"{} ".format(unicode(line_count)))
block = block.next()
painter.end()
return
示例8: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setFont [as 别名]
def paintEvent(self, event):
painter = QPainter()
painter.begin(self)
painter.setRenderHint(QPainter.HighQualityAntialiasing)
painter.setRenderHint(QPainter.SmoothPixmapTransform)
painter.setBrush(QColor(255, 255, 255))
painter.drawRect(QRect(0, -1, self.window().width(), 76))
if self.icon:
painter.drawPixmap(QRect(16, 16, 32, 32), self.icon)
if self.title:
painter.setFont(QFont("Roboto\\Roboto-Regular.ttf", 20))
if qt_ver() != "PySide":
painter.drawText(QRect(56, 0, 64, 48),0, self.title)
else:
painter.drawText(QRect(56, 0, 64, 48), self.title)
if self.text:
painter.setFont(QFont("Roboto\\Roboto-Regular.ttf", 13))
if qt_ver() != "PySide":
painter.drawText(QRect(56, self.height() / 2, self.window().width() - 56, 36),0, self.text)
painter.end()
示例9: _showRemainingTime
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setFont [as 别名]
def _showRemainingTime(self, seconds):
"""
Show remaining time to the user
@param seconds: remaining time
@type seconds: int
"""
if seconds > 60:
time = int(seconds / 60)
else:
time = seconds
text = "{0:02d}".format(time)
basePixelMap = resources.getPixelMap('pomidor.png')
painter = QPainter(basePixelMap)
painter.setFont(QFont("PT Sans", 64, QFont.Bold))
painter.setPen(QPen(QColor(0, 0, 0)))
painter.drawText(basePixelMap.rect(), Qt.AlignCenter, text)
painter.setFont(QFont("PT Sans", 58, QFont.Bold))
painter.setPen(QPen(QColor(240, 240, 240)))
painter.drawText(basePixelMap.rect(), Qt.AlignCenter, text)
painter.end()
self.__trayIcon.setIcon(QIcon(basePixelMap))
示例10: tag_image
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setFont [as 别名]
def tag_image(source, dest, tag, font, fontsize, x, y, width, height, aspectx, aspecty, red, green, blue, bold=False, italic=False):
"""docstring for tag_image"""
app = QApplication.instance()
pixmap = QPixmap(source)
color = QColor(red,green,blue)
font = QFont(font)
font.setPixelSize(int(fontsize*pixmap.height()))
font.setItalic(italic)
font.setBold(bold)
painter = QPainter(pixmap)
painter.setPen(color)
painter.setFont(font);
painter.drawText(x*pixmap.width(),y*pixmap.height(), tag)
painter.end()
# Resize and save
return pixmap.toImage().scaled(width*aspectx, height*aspecty, Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation).scaled(width, height, Qt.IgnoreAspectRatio, Qt.SmoothTransformation).save(dest)
示例11: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setFont [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)
示例12: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setFont [as 别名]
def paintEvent(self, event):
super().paintEvent(event)
painter = QPainter(self)
# Рисование цифр в ячейки таблицы
for i in range(self.matrix_size):
for j in range(self.matrix_size):
# Если текущая ячейка относится к дефолтной судоку
if self.def_num_matrix[i][j]:
painter.save()
# painter.setPen()
painter.setBrush(Qt.yellow)
x = i * self.cell_size
y = j * self.cell_size
w, h = self.cell_size, self.cell_size
painter.drawRect(x, y, w, h)
painter.restore()
# TODO: Закомментировано
# Если индекс ячейки под курсором валидный
if 0 <= self.x_highlight_cell < self.matrix_size and 0 <= self.y_highlight_cell < self.matrix_size:
# # Выделение всего столбца и строки пересекающих ячейку под курсором
# painter.save()
# painter.setBrush(Qt.lightGray)
#
# # Выделение строки
# for i in range(self.matrix_size):
# painter.drawRect(i * self.cell_size,
# self.y_highlight_cell * self.cell_size,
# self.cell_size,
# self.cell_size)
#
# # Выделение столбца
# for j in range(self.matrix_size):
# painter.drawRect(self.x_highlight_cell * self.cell_size,
# j * self.cell_size,
# self.cell_size,
# self.cell_size)
#
# painter.restore()
x, y = self.x_highlight_cell, self.y_highlight_cell
# Не подсвечиваем дефолтную ячейку
if not self.def_num_matrix[x][y]:
# Выделение ячейки под курсором
painter.save()
painter.setBrush(Qt.darkYellow)
painter.drawRect(x * self.cell_size,
y * self.cell_size,
self.cell_size,
self.cell_size)
painter.restore()
# Рисование цифр в ячейки таблицы
for i in range(self.matrix_size):
for j in range(self.matrix_size):
num = self.matrix[i][j]
if not num:
continue
num = str(num)
# Алгоритм изменения размера текста взят из http://stackoverflow.com/a/2204501
# Для текущего пришлось немного адаптировать
factor = (self.cell_size / 2) / painter.fontMetrics().width(num)
if factor < 1 or factor > 1.25:
f = painter.font()
point_size = f.pointSizeF() * factor
if point_size > 0:
f.setPointSizeF(point_size)
painter.setFont(f)
x = i * self.cell_size
y = j * self.cell_size
w, h = self.cell_size, self.cell_size
painter.drawText(x, y, w, h, Qt.AlignCenter, num)
# Рисование сетки таблицы
y1, y2 = 0, 0
factor = min(self.width(), self.height()) / self.default_size
size = self.default_pen_size_1
size2 = self.default_pen_size_2
if factor < 1 or factor > 1.25:
size *= factor
if size < self.min_default_pen_size_2:
size = self.min_default_pen_size_2
painter.save()
for i in range(self.matrix_size + 1):
painter.setPen(QPen(Qt.black, size2 if i % 3 == 0 and i and i < self.matrix_size else size))
painter.drawLine(0, y1, self.cell_size * self.matrix_size, y2)
y1 += self.cell_size
y2 += self.cell_size
#.........这里部分代码省略.........
示例13: add_labels_internal
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setFont [as 别名]
def add_labels_internal(self, gl, render_state, draw_to_canvas, labels):
'''
call to add a list of labels
'''
text_paint = QPainter()
if draw_to_canvas:
text_paint.begin(self.bitmap)
text_paint.setRenderHints(QPainter.Antialiasing)
u = 0
v = 0
line_height = 0
for label in labels:
ascent = 0
descent = 0
measured_text_width = 0
height = 0
width = 0
font_size = label.font_size
while True:
metrics = None
if draw_to_canvas:
mask = 0x000000FF
b = (label.color >> 16) & mask
g = (label.color >> 8) & mask
r = label.color & mask
######################################################################## LINE CHANGED
text_paint.setPen(QColor(0, 0, 0))
#text_paint.setPen(QColor(r, g, b))
# The value 0.75 is hard coded representing phone pixel density
text_paint.setFont(QFont('Veranda', font_size * 0.75))
# Paint.ascent is negative, so negate it.
metrics = text_paint.fontMetrics()
else:
# The value 0.75 is hard coded representing phone pixel density
metrics = QFontMetrics(QFont('Veranda', font_size * 0.75))
ascent = math.ceil(metrics.ascent())
descent = math.ceil(metrics.descent())
measured_text_width = math.ceil(metrics.boundingRect(label.string).width())
height = int(ascent) + int(descent)
width = int(measured_text_width)
# If it's wider than the screen, try it again with a font size of 1
# smaller.
font_size -= 1
if font_size < 0 or width < render_state.screen_width:
break
next_u = 0
# Is there room for this string on the current line?
if u + width > self.strike_width:
# No room, go to the next line:
u = 0
next_u = width
v += line_height
line_height = 0
else:
next_u = u + width
line_height = max(line_height, height)
if (v + line_height > self.strike_height) and draw_to_canvas:
raise Exception("out of texture space.")
v_base = v + ascent
if draw_to_canvas:
text_paint.drawText(int(u), int(v_base), label.string)
label.set_texture_data(width, height, u, v + height, width, -height,
self.texel_width, self.texel_height)
u = next_u
if draw_to_canvas:
text_paint.end()
return v + line_height
示例14: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setFont [as 别名]
def paintEvent( self, event ):
painter = QPainter()
painter.begin(self)
painter.setRenderHint(painter.Antialiasing)
font = painter.font()
font.setBold(True)
painter.setFont(font)
x = self.rect().x()
y = self.rect().y()
w = self.rect().width() - 1
h = self.rect().height() - 1
r = 8
# draw a rounded style
if self._rolloutStyle == 2:
# draw the text
painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())
# draw the triangle
self.__drawTriangle(painter, x, y)
# draw the borders
pen = QPen(self.palette().color(QPalette.Light))
pen.setWidthF(0.6)
painter.setPen(pen)
painter.drawRoundedRect(x + 1, y + 1, w - 1, h - 1, r, r)
pen.setColor(self.palette().color(QPalette.Shadow))
painter.setPen(pen)
painter.drawRoundedRect(x, y, w - 1, h - 1, r, r)
# draw a square style
if self._rolloutStyle == 3:
# draw the text
painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())
self.__drawTriangle(painter, x, y)
# draw the borders
pen = QPen(self.palette().color(QPalette.Light))
pen.setWidthF(0.6)
painter.setPen(pen)
painter.drawRect(x + 1, y + 1, w - 1, h - 1)
pen.setColor(self.palette().color(QPalette.Shadow))
painter.setPen(pen)
painter.drawRect(x, y, w - 1, h - 1)
# draw a Maya style
if self._rolloutStyle == 4:
# draw the text
painter.drawText(x + 33, y + 3, w, 16, Qt.AlignLeft | Qt.AlignTop, self.title())
painter.setRenderHint(QPainter.Antialiasing, False)
self.__drawTriangle(painter, x, y)
# draw the borders - top
headerHeight = 20
headerRect = QRect(x + 1, y + 1, w - 1, headerHeight)
headerRectShadow = QRect(x - 1, y - 1, w + 1, headerHeight + 2)
# Highlight
pen = QPen(self.palette().color(QPalette.Light))
pen.setWidthF(0.4)
painter.setPen(pen)
painter.drawRect(headerRect)
painter.fillRect(headerRect, QColor(255, 255, 255, 18))
# Shadow
pen.setColor(self.palette().color(QPalette.Dark))
painter.setPen(pen)
painter.drawRect(headerRectShadow)
if not self.isCollapsed():
# draw the lover border
pen = QPen(self.palette().color(QPalette.Dark))
pen.setWidthF(0.8)
painter.setPen(pen)
offSet = headerHeight + 3
bodyRect = QRect(x, y + offSet, w, h - offSet)
bodyRectShadow = QRect(x + 1, y + offSet, w + 1, h - offSet + 1)
painter.drawRect(bodyRect)
pen.setColor(self.palette().color(QPalette.Light))
pen.setWidthF(0.4)
painter.setPen(pen)
painter.drawRect(bodyRectShadow)
# draw a boxed style
elif self._rolloutStyle == 1:
#.........这里部分代码省略.........