本文整理汇总了Python中PySide.QtGui.QPainter.drawText方法的典型用法代码示例。如果您正苦于以下问题:Python QPainter.drawText方法的具体用法?Python QPainter.drawText怎么用?Python QPainter.drawText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QPainter
的用法示例。
在下文中一共展示了QPainter.drawText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawText [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)
示例2: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawText [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)
示例3: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawText [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)
示例4: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawText [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
示例5: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawText [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()
示例6: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawText [as 别名]
def paintEvent(self, event):
cX = self.parent.leftMargin + self.scaleMarkLen
cY = self.parent.topMargin + self.scaleMarkLen
worldX = self.parent.chunkX*16
worldZ = self.parent.chunkZ*16
painter = QPainter()
path = QPainterPath()
painter.begin(self)
painter.save()
#painter.setFont(QFont('Arial Narrow', 8)) #QFont.Bold
# draw scale
x = cX
y = cY
painter.rotate(-90)
for i in range(16):
fr = QRectF(-y, x, self.scaleMarkLen, self.edgeLen)
painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, '-5555')
painter.drawRect(fr)
#fr = QRectF(-y - 16*self.edgeLen - self.scaleMarkLen, x, self.scaleMarkLen, self.edgeLen)
#painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, '-5555')
#painter.drawRect(fr)
x += self.edgeLen
painter.rotate(90)
x = self.parent.leftMargin
y = cY
for i in range(16):
fr = QRectF(x, y, self.scaleMarkLen, self.edgeLen)
painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, '-5555')
painter.drawRect(fr)
#fr = QRectF(x + self.scaleMarkLen + 16*self.edgeLen, y, self.scaleMarkLen, self.edgeLen)
#painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, '-5555')
#painter.drawRect(fr)
y += self.edgeLen
x = cX
y = cY
for i in range(16):
for j in range(16):
path.addRect(x, y, self.edgeLen, self.edgeLen)
fr = QRectF(x, y, self.edgeLen, self.edgeLen)
#painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, '-5555')
x += self.edgeLen
x = cX
y += self.edgeLen
painter.drawPath(path)
painter.restore()
painter.end()
del painter
示例7: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawText [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
示例8: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawText [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()
示例9: createPixmap
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawText [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
示例10: _numberbar_paint
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawText [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
示例11: paintGL
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawText [as 别名]
def paintGL(self):
gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
gl.glUseProgram(self.shaders_program)
gl.glBegin(gl.GL_QUAD_STRIP)
bar_start = -1 + self.text_height / self.height() * 2
bar_height = (1 - 2 * self.text_height / self.height()) * 2
steps = 40
for i in xrange(steps + 1):
y = i * (1 / steps)
gl.glColor(y, 0, 0)
gl.glVertex(-0.5, (bar_height*y + bar_start), 0.0)
gl.glVertex(0.5, (bar_height*y + bar_start), 0.0)
gl.glEnd()
p = QPainter(self)
p.drawText((self.width() - self.vmax_width)/2, self.text_ascent, self.vmax_str)
p.drawText((self.width() - self.vmin_width)/2, self.height() - self.text_height + self.text_ascent,
self.vmin_str)
p.end()
示例12: tag_image
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawText [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)
示例13: _showRemainingTime
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawText [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))
示例14: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawText [as 别名]
def paintEvent(self, event):
painter = QPainter(self)
# Фон
painter_path = QPainterPath()
painter_path.addRect(0, 0, self.width() - 1, self.height() - 1)
painter.fillPath(painter_path,
QBrush(QImage(':/main/background.png')))
if self.image:
painter.drawText(10, 20, str(self.image.draw_scale))
painter.setTransform(QTransform().
scale(self.image.draw_scale, self.image.draw_scale).
translate(self.image.draw_offset.x(), self.image.draw_offset.y()))
old_pen = painter.pen()
new_pen = QPen()
new_pen.setColor(QColor(0, 150, 0))
painter.setPen(new_pen)
self.image.draw(painter)
painter.setPen(old_pen)
示例15: paintEvent
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import drawText [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()