本文整理汇总了Python中spyderlib.qt.QtGui.QTreeWidgetItem.font方法的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidgetItem.font方法的具体用法?Python QTreeWidgetItem.font怎么用?Python QTreeWidgetItem.font使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spyderlib.qt.QtGui.QTreeWidgetItem
的用法示例。
在下文中一共展示了QTreeWidgetItem.font方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: populate_tree
# 需要导入模块: from spyderlib.qt.QtGui import QTreeWidgetItem [as 别名]
# 或者: from spyderlib.qt.QtGui.QTreeWidgetItem import font [as 别名]
def populate_tree(self):
"""Create each item (and associated data) in the tree"""
if not self.stats:
warn_item = QTreeWidgetItem(self)
warn_item.setData(
0, Qt.DisplayRole,
_('No timings to display. '
'Did you forget to add @profile decorators ?')
.format(url=WEBSITE_URL))
warn_item.setFirstColumnSpanned(True)
warn_item.setTextAlignment(0, Qt.AlignCenter)
font = warn_item.font(0)
font.setStyle(QFont.StyleItalic)
warn_item.setFont(0, font)
return
try:
monospace_font = self.window().editor.get_plugin_font()
except AttributeError: # If run standalone for testing
monospace_font = QFont("Courier New")
monospace_font.setPointSize(10)
for func_info, func_data in self.stats.items():
# Function name and position
filename, start_line_no, func_name = func_info
func_stats, func_peak_usage = func_data
func_item = QTreeWidgetItem(self)
func_item.setData(
0, Qt.DisplayRole,
_('{func_name} (peak {peak_usage:.3f} MiB) in file "{filename}", '
'line {line_no}').format(
filename=filename,
line_no=start_line_no,
func_name=func_name,
peak_usage=func_peak_usage))
func_item.setFirstColumnSpanned(True)
func_item.setData(COL_POS, Qt.UserRole,
(osp.normpath(filename), start_line_no))
# For sorting by time
func_item.setData(COL_USAGE, Qt.DisplayRole, func_peak_usage)
func_item.setData(COL_INCREMENT, Qt.DisplayRole,
func_peak_usage)
if self.parent().use_colors:
# Choose deteministic unique color for the function
md5 = hashlib.md5((filename + func_name).encode("utf8")).hexdigest()
hue = (int(md5[:2], 16) - 68) % 360 # avoid blue (unreadable)
func_color = QColor.fromHsv(hue, 200, 255)
else:
# Red color only
func_color = QColor.fromRgb(255, 0, 0)
# get max increment
max_increment = 0
for line_info in func_stats:
(line_no, code_line, usage, increment) = line_info
if increment is not None:
max_increment = max(max_increment, increment)
# Lines of code
for line_info in func_stats:
line_item = QTreeWidgetItem(func_item)
(line_no, code_line, usage, increment) = line_info
self.fill_item(
line_item, filename, line_no, code_line,
usage, increment)
# Color background
if increment is not None:
alpha = increment / max_increment if max_increment != 0 else 0
color = QColor(func_color)
color.setAlphaF(alpha) # Returns None
color = QBrush(color)
for col in range(self.columnCount()):
line_item.setBackground(col, color)
else:
for col in range(self.columnCount()):
line_item.setForeground(col, CODE_NOT_RUN_COLOR)
# Monospace font for code
line_item.setFont(COL_LINE, monospace_font)