本文整理汇总了Python中qtpy.QtWidgets.QLabel.fontMetrics方法的典型用法代码示例。如果您正苦于以下问题:Python QLabel.fontMetrics方法的具体用法?Python QLabel.fontMetrics怎么用?Python QLabel.fontMetrics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QLabel
的用法示例。
在下文中一共展示了QLabel.fontMetrics方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fix_size
# 需要导入模块: from qtpy.QtWidgets import QLabel [as 别名]
# 或者: from qtpy.QtWidgets.QLabel import fontMetrics [as 别名]
def fix_size(self, content, extra=50):
"""
Adjusts the width and height of the file switcher,
based on its content.
"""
# Update size of dialog based on longest shortened path
strings = []
if content:
for rich_text in content:
label = QLabel(rich_text)
label.setTextFormat(Qt.PlainText)
strings.append(label.text())
fm = label.fontMetrics()
# Max width
max_width = max([fm.width(s) * 1.3 for s in strings])
self.list.setMinimumWidth(max_width + extra)
# Max height
if len(strings) < 8:
max_entries = len(strings)
else:
max_entries = 8
max_height = fm.height() * max_entries * 2.5
self.list.setMinimumHeight(max_height)
# Set position according to size
self.set_dialog_position()
示例2: fix_size
# 需要导入模块: from qtpy.QtWidgets import QLabel [as 别名]
# 或者: from qtpy.QtWidgets.QLabel import fontMetrics [as 别名]
def fix_size(self, content, extra=50):
"""Adjusts the width of the file switcher, based on the content."""
# Update size of dialog based on longest shortened path
strings = []
if content:
for rich_text in content:
label = QLabel(rich_text)
label.setTextFormat(Qt.PlainText)
strings.append(label.text())
fm = label.fontMetrics()
max_width = max([fm.width(s)*1.3 for s in strings])
self.list.setMinimumWidth(max_width + extra)
self.set_dialog_position()
示例3: get_item_size
# 需要导入模块: from qtpy.QtWidgets import QLabel [as 别名]
# 或者: from qtpy.QtWidgets.QLabel import fontMetrics [as 别名]
def get_item_size(self, content):
"""
Get the max size (width and height) for the elements of a list of
strings as a QLabel.
"""
strings = []
if content:
for rich_text in content:
label = QLabel(rich_text)
label.setTextFormat(Qt.PlainText)
strings.append(label.text())
fm = label.fontMetrics()
return (max([fm.width(s) * 1.3 for s in strings]), fm.height())
示例4: BaseTimerStatus
# 需要导入模块: from qtpy.QtWidgets import QLabel [as 别名]
# 或者: from qtpy.QtWidgets.QLabel import fontMetrics [as 别名]
class BaseTimerStatus(StatusBarWidget):
"""Status bar widget base for widgets that update based on timers."""
TITLE = None
TIP = None
def __init__(self, parent, statusbar):
"""Status bar widget base for widgets that update based on timers."""
super(BaseTimerStatus, self).__init__(parent, statusbar)
# Widgets
self.label = QLabel(self.TITLE)
self.value = QLabel()
# Widget setup
self.setToolTip(self.TIP)
self.value.setAlignment(Qt.AlignRight)
self.value.setFont(self.label_font)
fm = self.value.fontMetrics()
self.value.setMinimumWidth(fm.width('000%'))
# Layout
layout = self.layout()
layout.addWidget(self.label)
layout.addWidget(self.value)
layout.addSpacing(20)
# Setup
if self.is_supported():
self.timer = QTimer()
self.timer.timeout.connect(self.update_label)
self.timer.start(2000)
else:
self.timer = None
self.hide()
def set_interval(self, interval):
"""Set timer interval (ms)."""
if self.timer is not None:
self.timer.setInterval(interval)
def import_test(self):
"""Raise ImportError if feature is not supported."""
raise NotImplementedError
def is_supported(self):
"""Return True if feature is supported."""
try:
self.import_test()
return True
except ImportError:
return False
def get_value(self):
"""Return value (e.g. CPU or memory usage)."""
raise NotImplementedError
def update_label(self):
"""Update status label widget, if widget is visible."""
if self.isVisible():
self.value.setText('%d %%' % self.get_value())