本文整理汇总了Python中PySide.QtGui.QPainter.setRenderHints方法的典型用法代码示例。如果您正苦于以下问题:Python QPainter.setRenderHints方法的具体用法?Python QPainter.setRenderHints怎么用?Python QPainter.setRenderHints使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QPainter
的用法示例。
在下文中一共展示了QPainter.setRenderHints方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_labels_internal
# 需要导入模块: from PySide.QtGui import QPainter [as 别名]
# 或者: from PySide.QtGui.QPainter import setRenderHints [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