Python PyQt5.QtGui 模块,QFontMetricsF() 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用PyQt5.QtGui.QFontMetricsF()

项目:brown    作者:ajyoon    | 项目源码 | 文件源码
def __init__(self, brown_object, family_name, size, weight, italic):
        """
        Args:
            brown_object (Brush): The object this interface belongs to
            family_name (str): The name of the font family
            size (Unit): The size of the font
            weight (int or None): The font weight. If `None`,
                a normal weight will be used.
            italic (bool): Italicized or not
        """
        super().__init__(brown_object)
        self.family_name = family_name
        self.size = size
        self.weight = weight
        self.italic = italic
        self.qt_object = QtGui.QFont(
            self.family_name,
            GraphicUnit(self.size).value,
            self.weight if self.weight is not None else -1,
            self.italic)
        self._qt_font_info_object = QtGui.QFontInfo(self.qt_object)
        self._qt_font_metrics_object = QtGui.QFontMetricsF(
            self.qt_object,
            brown._app_interface.view)

    ######## PUBLIC PROPERTIES ########
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def rescale(self):

        fm = QFontMetricsF(self._font, self)
        maxRect = fm.boundingRect(QRectF(self.rect()), Qt.AlignCenter,
                str(self._maximum))
        xscale = float(self.width())/maxRect.width()
        yscale = float(self.height())/maxRect.height()
        self._scale = min(xscale, yscale)
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def reposition(self):

        fm = QFontMetricsF(self._font, self)
        rect = fm.boundingRect(QRectF(self.rect()), Qt.AlignCenter,
                str(self._value))
        self._xpos = -rect.width()/2.0
        self._ypos = rect.height()/2.0 - fm.descent()
        self.update()

    # Provide getter and setter methods for the font property.
项目:examples    作者:pyqt    | 项目源码 | 文件源码
def rescale(self):

        fm = QFontMetricsF(self._font, self)
        maxRect = fm.boundingRect(QRectF(self.rect()), Qt.AlignCenter,
                str(self._maximum))
        xscale = float(self.width())/maxRect.width()
        yscale = float(self.height())/maxRect.height()
        self._scale = min(xscale, yscale)
项目:examples    作者:pyqt    | 项目源码 | 文件源码
def reposition(self):

        fm = QFontMetricsF(self._font, self)
        rect = fm.boundingRect(QRectF(self.rect()), Qt.AlignCenter,
                str(self._value))
        self._xpos = -rect.width()/2.0
        self._ypos = rect.height()/2.0 - fm.descent()
        self.update()

    # Provide getter and setter methods for the font property.
项目:songscreen    作者:maccesch    | 项目源码 | 文件源码
def _add_line(self, scene, line_index, left, text_str, font, color, offset=0, align_right=False):
        y = self._line_height * line_index + offset + self.h * 0.1

        if line_index == 1:
            self._first_lyrics_line_y = y

        metrics = QFontMetricsF(font)
        text_width = metrics.width(text_str)
        max_text_width = (self.w - left - left)
        overflow = text_width - max_text_width

        if overflow <= 0:
            text = scene.addText(text_str, font)
            if align_right:
                text.setPos(self.w - left - text_width, y)
            else:
                text.setPos(left, y)
            text.setDefaultTextColor(color)
        else:
            scale_factor = max_text_width / text_width
            if scale_factor >= 0.9:
                text = scene.addText(text_str, font)
                text.setPos(left, y)
                text.setDefaultTextColor(color)
                text.setTransform(QTransform().scale(scale_factor, 1.0))
            else:
                self._extra_lines_after.append(line_index)

                idx = len(text_str) // 2
                while idx < len(text_str) and not text_str[idx].isspace():
                    idx += 1

                line_index = self._add_line(scene, line_index, left, text_str[:idx], font, color, offset)
                line_index += 1
                line_index = self._add_line(scene, line_index, left, "\t" + text_str[idx:], font, color,
                                            offset - self._line_height * 0.1)

        return line_index
项目:songscreen    作者:maccesch    | 项目源码 | 文件源码
def _calc_line_height(self, font):
        metrics = QFontMetricsF(font)
        line_height = metrics.height() * self.line_height_factor
        return line_height
项目:pyqt5-example    作者:guinslym    | 项目源码 | 文件源码
def rescale(self):

        fm = QFontMetricsF(self._font, self)
        maxRect = fm.boundingRect(QRectF(self.rect()), Qt.AlignCenter,
                str(self._maximum))
        xscale = float(self.width())/maxRect.width()
        yscale = float(self.height())/maxRect.height()
        self._scale = min(xscale, yscale)
项目:pyqt5-example    作者:guinslym    | 项目源码 | 文件源码
def reposition(self):

        fm = QFontMetricsF(self._font, self)
        rect = fm.boundingRect(QRectF(self.rect()), Qt.AlignCenter,
                str(self._value))
        self._xpos = -rect.width()/2.0
        self._ypos = rect.height()/2.0 - fm.descent()
        self.update()

    # Provide getter and setter methods for the font property.