当前位置: 首页>>代码示例>>Python>>正文


Python QLabel.fontMetrics方法代码示例

本文整理汇总了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()
开发者ID:ShenggaoZhu,项目名称:spyder,代码行数:30,代码来源:fileswitcher.py

示例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()
开发者ID:JamesLTaylor,项目名称:spyder,代码行数:15,代码来源:fileswitcher.py

示例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())
开发者ID:rlaverde,项目名称:spyder,代码行数:16,代码来源:fileswitcher.py

示例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())
开发者ID:0xBADCA7,项目名称:spyder,代码行数:63,代码来源:status.py


注:本文中的qtpy.QtWidgets.QLabel.fontMetrics方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。