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


Python Qt.QFontMetrics类代码示例

本文整理汇总了Python中PyQt5.Qt.QFontMetrics的典型用法代码示例。如果您正苦于以下问题:Python QFontMetrics类的具体用法?Python QFontMetrics怎么用?Python QFontMetrics使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QFontMetrics类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

 def __init__(self, develop=False):
     self.drawn_once = False
     self.develop = develop
     self.title_font = f = QFont()
     f.setPointSize(self.TITLE_SIZE)
     f.setBold(True)
     self.title_height = QFontMetrics(f).lineSpacing() + 2
     self.body_font = f = QFont()
     f.setPointSize(self.BODY_SIZE)
     self.line_height = QFontMetrics(f).lineSpacing()
     self.total_height = max(self.LOGO_SIZE, self.title_height + 3 * self.line_height)
     self.num_font = f = QFont()
     f.setPixelSize(self.total_height)
     f.setItalic(True), f.setBold(True)
     f = QFontMetrics(f)
     self.num_ch = str(max(3, numeric_version[0]))
     self.footer_font = f = QFont()
     f.setPointSize(self.FOOTER_SIZE)
     f.setItalic(True)
     self.dpr = QApplication.instance().devicePixelRatio()
     self.pmap = QPixmap(I('library.png', allow_user_override=False))
     self.pmap.setDevicePixelRatio(self.dpr)
     self.pmap = self.pmap.scaled(int(self.dpr * self.LOGO_SIZE), int(self.dpr * self.LOGO_SIZE), transformMode=Qt.SmoothTransformation)
     self.light_brush = QBrush(QColor('#F6F3E9'))
     self.dark_brush = QBrush(QColor('#39322B'))
     pmap = QPixmap(int(self.WIDTH * self.dpr), int(self.WIDTH * self.dpr))
     pmap.setDevicePixelRatio(self.dpr)
     pmap.fill(Qt.transparent)
     QSplashScreen.__init__(self, pmap)
     self.setWindowTitle(__appname__)
开发者ID:MarioJC,项目名称:calibre,代码行数:30,代码来源:splash_screen.py

示例2: __init__

    def __init__(self, text='', width=0, font=None, img=None, max_height=100, align=Qt.AlignCenter):
        self.layouts = []
        self._position = Point(0, 0)
        self.leading = self.line_spacing = 0
        if font is not None:
            fm = QFontMetrics(font, img)
            self.leading = fm.leading()
            self.line_spacing = fm.lineSpacing()
        for text in text.split('<br>') if text else ():
            text, formats = parse_text_formatting(sanitize(text))
            l = QTextLayout(unescape_formatting(text), font, img)
            l.setAdditionalFormats(formats)
            to = QTextOption(align)
            to.setWrapMode(QTextOption.WrapAtWordBoundaryOrAnywhere)
            l.setTextOption(to)

            l.beginLayout()
            height = 0
            while height + 3*self.leading < max_height:
                line = l.createLine()
                if not line.isValid():
                    break
                line.setLineWidth(width)
                height += self.leading
                line.setPosition(QPointF(0, height))
                height += line.height()
            max_height -= height
            l.endLayout()
            if self.layouts:
                self.layouts.append(self.leading)
            else:
                self._position = Point(l.position().x(), l.position().y())
            self.layouts.append(l)
        if self.layouts:
            self.layouts.append(self.leading)
开发者ID:artbycrunk,项目名称:calibre,代码行数:35,代码来源:covers.py

示例3: formatText

 def formatText(self, font):
     metrics = QFontMetrics(font)
     width = metrics.width(self.text)
     
     need_to_modify = False
     
     while(width > Words.MAXIMUM_TEXT_WIDTH):
         need_to_modify = True
         self.text = self.text[0:-1]
         width = metrics.width(self.text)
     
     if need_to_modify:
         self.text = self.text[0:-3]
         self.text = self.text + "..."
开发者ID:artemmoskalev,项目名称:stickman_animator,代码行数:14,代码来源:World.py

示例4: __init__

 def __init__(self, button, parent=None):
     QWidget.__init__(self, parent)
     self.mouse_over = False
     self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
     self.button = button
     self.text = button.label
     self.setCursor(Qt.PointingHandCursor)
     self.fm = QFontMetrics(self.font())
     self._bi = self._di = None
开发者ID:JimmXinu,项目名称:calibre,代码行数:9,代码来源:layout_menu.py

示例5: __init__

    def __init__(self, title, msg=u'\u00a0', min=0, max=99, parent=None, cancelable=True, icon=None):
        QDialog.__init__(self, parent)
        if icon is None:
            self.l = l = QVBoxLayout(self)
        else:
            self.h = h = QHBoxLayout(self)
            self.icon = i = QLabel(self)
            if not isinstance(icon, QIcon):
                icon = QIcon(I(icon))
            i.setPixmap(icon.pixmap(64))
            h.addWidget(i, alignment=Qt.AlignTop | Qt.AlignHCenter)
            self.l = l = QVBoxLayout()
            h.addLayout(l)
            self.setWindowIcon(icon)

        self.title_label = t = QLabel(title)
        self.setWindowTitle(title)
        t.setStyleSheet('QLabel { font-weight: bold }'), t.setAlignment(Qt.AlignCenter), t.setTextFormat(Qt.PlainText)
        l.addWidget(t)

        self.bar = b = QProgressBar(self)
        b.setMinimum(min), b.setMaximum(max), b.setValue(min)
        l.addWidget(b)

        self.message = m = QLabel(self)
        fm = QFontMetrics(self.font())
        m.setAlignment(Qt.AlignCenter), m.setMinimumWidth(fm.averageCharWidth() * 80), m.setTextFormat(Qt.PlainText)
        l.addWidget(m)
        self.msg = msg

        self.button_box = bb = QDialogButtonBox(QDialogButtonBox.Abort, self)
        bb.rejected.connect(self._canceled)
        l.addWidget(bb)

        self.setWindowModality(Qt.ApplicationModal)
        self.canceled = False

        if not cancelable:
            bb.setVisible(False)
        self.cancelable = cancelable
        self.resize(self.sizeHint())
开发者ID:j-howell,项目名称:calibre,代码行数:41,代码来源:progress.py

示例6: populate

    def populate(self, phrase, ts, process_space=True):
        phrase_pos = 0
        processed = False
        matches = self.__class__.whitespace.finditer(phrase)
        font = QFont(ts.font)
        if self.valign is not None:
            font.setPixelSize(font.pixelSize()/1.5)
        fm = QFontMetrics(font)
        single_space_width = fm.width(' ')
        height, descent = fm.height(), fm.descent()
        for match in matches:
            processed = True
            left, right = match.span()
            if not process_space:
                right = left
            space_width = single_space_width * (right-left)
            word = phrase[phrase_pos:left]
            width = fm.width(word)
            if self.current_width + width < self.line_length:
                self.commit(word, width, height, descent, ts, font)
                if space_width > 0 and self.current_width + space_width < self.line_length:
                    self.add_space(space_width)
                phrase_pos = right
                continue

            # Word doesn't fit on line
            if self.hyphenate and len(word) > 3:
                tokens = hyphenate_word(word)
                for i in range(len(tokens)-2, -1, -1):
                    word = ''.join(tokens[0:i+1])+'-'
                    width = fm.width(word)
                    if self.current_width + width < self.line_length:
                        self.commit(word, width, height, descent, ts, font)
                        return phrase_pos + len(word)-1, True
            if self.current_width < 5:  # Force hyphenation as word is longer than line
                for i in range(len(word)-5, 0, -5):
                    part = word[:i] + '-'
                    width = fm.width(part)
                    if self.current_width + width < self.line_length:
                        self.commit(part, width, height, descent, ts, font)
                        return phrase_pos + len(part)-1, True
            # Failed to add word.
            return phrase_pos, True

        if not processed:
            return self.populate(phrase+' ', ts, False)

        return phrase_pos, False
开发者ID:Farb,项目名称:calibre,代码行数:48,代码来源:text.py

示例7: sizeHint

 def sizeHint(self):
     fm = QFontMetrics(self.font())
     ans = QPlainTextEdit.sizeHint(self)
     ans.setWidth(fm.averageCharWidth() * 50)
     return ans
开发者ID:j-howell,项目名称:calibre,代码行数:5,代码来源:proceed.py

示例8: sizeHint

 def sizeHint(self):
     fm = QFontMetrics(self.font())
     return QSize(fm.averageCharWidth() * 120, 600)
开发者ID:davidfor,项目名称:calibre,代码行数:3,代码来源:function_replace.py

示例9: do_size_hint

 def do_size_hint(self, option, index):
     text = index.data(Qt.DisplayRole) or ''
     font = QFont(option.font)
     font.setPointSize(QFontInfo(font).pointSize() * 1.5)
     m = QFontMetrics(font)
     return QSize(m.width(text), m.height())
开发者ID:MarioJC,项目名称:calibre,代码行数:6,代码来源:font_family_chooser.py

示例10: LayoutItem

class LayoutItem(QWidget):

    def __init__(self, button, parent=None):
        QWidget.__init__(self, parent)
        self.mouse_over = False
        self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.button = button
        self.text = button.label
        self.setCursor(Qt.PointingHandCursor)
        self.fm = QFontMetrics(self.font())
        self._bi = self._di = None

    @property
    def bright_icon(self):
        if self._bi is None:
            self._bi = self.button.icon().pixmap(ICON_SZ, ICON_SZ)
        return self._bi

    @property
    def dull_icon(self):
        if self._di is None:
            self._di = self.button.icon().pixmap(ICON_SZ, ICON_SZ, mode=QIcon.Disabled)
        return self._di

    def event(self, ev):
        m = None
        et = ev.type()
        if et == ev.Enter:
            m = True
        elif et == ev.Leave:
            m = False
        if m is not None and m != self.mouse_over:
            self.mouse_over = m
            self.update()
        return QWidget.event(self, ev)

    def sizeHint(self):
        br = self.fm.boundingRect(self.text)
        w = max(br.width(), ICON_SZ) + 10
        h = 2 * self.fm.lineSpacing() + ICON_SZ + 8
        return QSize(w, h)

    def paintEvent(self, ev):
        shown = self.button.isChecked()
        ls = self.fm.lineSpacing()
        painter = QPainter(self)
        if self.mouse_over:
            tool = QStyleOption()
            tool.rect = self.rect()
            tool.state = QStyle.State_Raised | QStyle.State_Active | QStyle.State_MouseOver
            s = self.style()
            s.drawPrimitive(QStyle.PE_PanelButtonTool, tool, painter, self)
        painter.drawText(
            0, 0,
            self.width(),
            ls, Qt.AlignCenter | Qt.TextSingleLine, self.text)
        text = _('Hide') if shown else _('Show')
        f = self.font()
        f.setBold(True)
        painter.setFont(f)
        painter.drawText(
            0, self.height() - ls,
            self.width(),
            ls, Qt.AlignCenter | Qt.TextSingleLine, text)
        x = (self.width() - ICON_SZ) // 2
        y = ls + (self.height() - ICON_SZ - 2 * ls) // 2
        pmap = self.bright_icon if shown else self.dull_icon
        painter.drawPixmap(x, y, pmap)
        painter.end()
开发者ID:JimmXinu,项目名称:calibre,代码行数:69,代码来源:layout_menu.py

示例11: __init__


#.........这里部分代码省略.........
                last_annotation,
                book_data['annotations'],
                confidence]
            self.tabledata.append(this_book)

        self.tv = QTableView(self)
        self.l.addWidget(self.tv)
        self.annotations_header = ['uuid', 'book_id', 'genre', '', 'Reader App', 'Title',
                                   'Author', 'Last Annotation', 'Annotations', 'Confidence']
        self.ENABLED_COL = 3
        self.READER_APP_COL = 4
        self.TITLE_COL = 5
        self.AUTHOR_COL = 6
        self.LAST_ANNOTATION_COL = 7
        self.CONFIDENCE_COL = 9
        columns_to_center = [8]
        self.tm = MarkupTableModel(self, columns_to_center=columns_to_center)
        self.tv.setModel(self.tm)
        self.tv.setShowGrid(False)
        self.tv.setFont(self.FONT)
        self.tvSelectionModel = self.tv.selectionModel()
        self.tv.setAlternatingRowColors(not self.show_confidence_colors)
        self.tv.setShowGrid(False)
        self.tv.setWordWrap(False)
        self.tv.setSelectionBehavior(self.tv.SelectRows)

        # Connect signals
        self.tv.doubleClicked.connect(self.getTableRowDoubleClick)
        self.tv.horizontalHeader().sectionClicked.connect(self.capture_sort_column)

        # Hide the vertical self.header
        self.tv.verticalHeader().setVisible(False)

        # Hide uuid, book_id, genre, confidence
        self.tv.hideColumn(self.annotations_header.index('uuid'))
        self.tv.hideColumn(self.annotations_header.index('book_id'))
        self.tv.hideColumn(self.annotations_header.index('genre'))
        self.tv.hideColumn(self.annotations_header.index('Confidence'))

        # Set horizontal self.header props
        self.tv.horizontalHeader().setStretchLastSection(True)

        narrow_columns = ['Last Annotation', 'Reader App', 'Annotations']
        extra_width = 10
        breathing_space = 20

        # Set column width to fit contents
        self.tv.resizeColumnsToContents()
        perfect_width = 10 + (len(narrow_columns) * extra_width)
        for i in range(3, 8):
            perfect_width += self.tv.columnWidth(i) + breathing_space
        self.tv.setMinimumSize(perfect_width, 100)
        self.perfect_width = perfect_width

        # Add some width to narrow columns
        for nc in narrow_columns:
            cw = self.tv.columnWidth(self.annotations_header.index(nc))
            self.tv.setColumnWidth(self.annotations_header.index(nc), cw + extra_width)

        # Set row height
        fm = QFontMetrics(self.FONT)
        nrows = len(self.tabledata)
        for row in xrange(nrows):
            self.tv.setRowHeight(row, fm.height() + 4)

        self.tv.setSortingEnabled(True)
        sort_column = self.opts.prefs.get('annotated_books_dialog_sort_column',
                                          self.annotations_header.index('Confidence'))
        sort_order = self.opts.prefs.get('annotated_books_dialog_sort_order',
                                         Qt.DescendingOrder)
        self.tv.sortByColumn(sort_column, sort_order)

        # ~~~~~~~~ Create the ButtonBox ~~~~~~~~
        self.dialogButtonBox = QDialogButtonBox(QDialogButtonBox.Cancel | QDialogButtonBox.Help)
        self.dialogButtonBox.setOrientation(Qt.Horizontal)
        self.import_button = self.dialogButtonBox.addButton(self.dialogButtonBox.Ok)
        self.import_button.setText('Import Annotations')

        # Action buttons
        self.toggle_checkmarks_button = self.dialogButtonBox.addButton('Clear All', QDialogButtonBox.ActionRole)
        self.toggle_checkmarks_button.setObjectName('toggle_checkmarks_button')

        scb_text = 'Show match status'
        if self.show_confidence_colors:
            scb_text = "Hide match status"
        self.show_confidence_button = self.dialogButtonBox.addButton(scb_text, QDialogButtonBox.ActionRole)
        self.show_confidence_button.setObjectName('confidence_button')
        if self.show_confidence_colors:
            self.show_confidence_button.setIcon(get_icon('images/matches_hide.png'))
        else:
            self.show_confidence_button.setIcon(get_icon('images/matches_show.png'))

        self.preview_button = self.dialogButtonBox.addButton('Preview', QDialogButtonBox.ActionRole)
        self.preview_button.setObjectName('preview_button')

        self.dialogButtonBox.clicked.connect(self.show_annotated_books_dialog_clicked)
        self.l.addWidget(self.dialogButtonBox)

        # Cause our dialog size to be restored from prefs or created on first usage
        self.resize_dialog()
开发者ID:mkarpiarz,项目名称:calibre-annotations,代码行数:101,代码来源:annotated_books.py


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