當前位置: 首頁>>代碼示例>>Python>>正文


Python QtGui.QFontMetrics方法代碼示例

本文整理匯總了Python中qtpy.QtGui.QFontMetrics方法的典型用法代碼示例。如果您正苦於以下問題:Python QtGui.QFontMetrics方法的具體用法?Python QtGui.QFontMetrics怎麽用?Python QtGui.QFontMetrics使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在qtpy.QtGui的用法示例。


在下文中一共展示了QtGui.QFontMetrics方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from qtpy import QtGui [as 別名]
# 或者: from qtpy.QtGui import QFontMetrics [as 別名]
def __init__(self, value='', parent=None, get_pos=None):
        super().__init__(value, parent=parent)
        self.fm = QFontMetrics(QFont("", 0))
        self.setObjectName('slice_label')
        self.min_width = 30
        self.max_width = 200
        self.setCursor(Qt.IBeamCursor)
        self.setValidator(QDoubleValidator())
        self.textChanged.connect(self._on_text_changed)
        self._on_text_changed(value)

        self.get_pos = get_pos
        if parent is not None:
            self.min_width = 50
            self.slider = parent.slider
            self.setAlignment(Qt.AlignCenter) 
開發者ID:napari,項目名稱:napari,代碼行數:18,代碼來源:qt_range_slider_popup.py

示例2: _resize_axis_labels

# 需要導入模塊: from qtpy import QtGui [as 別名]
# 或者: from qtpy.QtGui import QFontMetrics [as 別名]
def _resize_axis_labels(self):
        """When any of the labels get updated, this method updates all label
        widths to the width of the longest label. This keeps the sliders
        left-aligned and allows the full label to be visible at all times,
        with minimal space, without setting stretch on the layout.
        """
        fm = QFontMetrics(QFont("", 0))
        labels = self.findChildren(QLineEdit, 'axis_label')
        newwidth = max([fm.boundingRect(lab.text()).width() for lab in labels])

        if any(self._displayed_sliders):
            # set maximum width to no more than 20% of slider width
            maxwidth = self.slider_widgets[0].width() * 0.2
            newwidth = min([newwidth, maxwidth])
        for labl in labels:
            labl.setFixedWidth(newwidth + 10) 
開發者ID:napari,項目名稱:napari,代碼行數:18,代碼來源:qt_dims.py

示例3: _resize_slice_labels

# 需要導入模塊: from qtpy import QtGui [as 別名]
# 或者: from qtpy.QtGui import QFontMetrics [as 別名]
def _resize_slice_labels(self):
        """When the size of any dimension changes, we want to resize all of the
        slice labels to width of the longest label, to keep all the sliders
        right aligned.  The width is determined by the number of digits in the
        largest dimensions, plus a little padding.
        """
        width = 0
        for ax, maxi in enumerate(self.dims.max_indices):
            if self._displayed_sliders[ax]:
                length = len(str(int(maxi)))
                if length > width:
                    width = length
        # gui width of a string of length `width`
        fm = QFontMetrics(QFont("", 0))
        width = fm.boundingRect("8" * width).width()
        for labl in self.findChildren(QWidget, 'slice_label'):
            labl.setFixedWidth(width + 6) 
開發者ID:napari,項目名稱:napari,代碼行數:19,代碼來源:qt_dims.py

示例4: _format_as_columns

# 需要導入模塊: from qtpy import QtGui [as 別名]
# 或者: from qtpy.QtGui import QFontMetrics [as 別名]
def _format_as_columns(self, items, separator='  '):
        """ Transform a list of strings into a single string with columns.

        Parameters
        ----------
        items : sequence of strings
            The strings to process.

        separator : str, optional [default is two spaces]
            The string that separates columns.

        Returns
        -------
        The formatted string.
        """
        # Calculate the number of characters available.
        width = self._control.document().textWidth()
        char_width = QtGui.QFontMetrics(self.font).boundingRect(' ').width()
        displaywidth = max(10, (width / char_width) - 1)

        return columnize(items, separator, displaywidth) 
開發者ID:jupyter,項目名稱:qtconsole,代碼行數:23,代碼來源:console_widget.py

示例5: sizeHint

# 需要導入模塊: from qtpy import QtGui [as 別名]
# 或者: from qtpy.QtGui import QFontMetrics [as 別名]
def sizeHint(self):
        """ Reimplemented to suggest a size that is 80 characters wide and
            25 lines high.
        """
        font_metrics = QtGui.QFontMetrics(self.font)
        margin = (self._control.frameWidth() +
                  self._control.document().documentMargin()) * 2
        style = self.style()
        splitwidth = style.pixelMetric(QtWidgets.QStyle.PM_SplitterWidth)

        # Note 1: Despite my best efforts to take the various margins into
        # account, the width is still coming out a bit too small, so we include
        # a fudge factor of one character here.
        # Note 2: QFontMetrics.maxWidth is not used here or anywhere else due
        # to a Qt bug on certain Mac OS systems where it returns 0.
        width = font_metrics.boundingRect(' ').width() * self.console_width + margin
        width += style.pixelMetric(QtWidgets.QStyle.PM_ScrollBarExtent)

        if self.paging == 'hsplit':
            width = width * 2 + splitwidth

        height = font_metrics.height() * self.console_height + margin
        if self.paging == 'vsplit':
            height = height * 2 + splitwidth

        return QtCore.QSize(int(width), int(height))

    #---------------------------------------------------------------------------
    # 'ConsoleWidget' public interface
    #--------------------------------------------------------------------------- 
開發者ID:jupyter,項目名稱:qtconsole,代碼行數:32,代碼來源:console_widget.py

示例6: _set_font

# 需要導入模塊: from qtpy import QtGui [as 別名]
# 或者: from qtpy.QtGui import QFontMetrics [as 別名]
def _set_font(self, font):
        """ Sets the base font for the ConsoleWidget to the specified QFont.
        """
        font_metrics = QtGui.QFontMetrics(font)
        self._control.setTabStopWidth(
            self.tab_width * font_metrics.boundingRect(' ').width()
        )

        self._completion_widget.setFont(font)
        self._control.document().setDefaultFont(font)
        if self._page_control:
            self._page_control.document().setDefaultFont(font)

        self.font_changed.emit(font) 
開發者ID:jupyter,項目名稱:qtconsole,代碼行數:16,代碼來源:console_widget.py

示例7: _set_tab_width

# 需要導入模塊: from qtpy import QtGui [as 別名]
# 或者: from qtpy.QtGui import QFontMetrics [as 別名]
def _set_tab_width(self, tab_width):
        """ Sets the width (in terms of space characters) for tab characters.
        """
        font_metrics = QtGui.QFontMetrics(self.font)
        self._control.setTabStopWidth(tab_width * font_metrics.boundingRect(' ').width())

        self._tab_width = tab_width 
開發者ID:jupyter,項目名稱:qtconsole,代碼行數:9,代碼來源:console_widget.py

示例8: _page

# 需要導入模塊: from qtpy import QtGui [as 別名]
# 或者: from qtpy.QtGui import QFontMetrics [as 別名]
def _page(self, text, html=False):
        """ Displays text using the pager if it exceeds the height of the
        viewport.

        Parameters
        ----------
        html : bool, optional (default False)
            If set, the text will be interpreted as HTML instead of plain text.
        """
        line_height = QtGui.QFontMetrics(self.font).height()
        minlines = self._control.viewport().height() / line_height
        if self.paging != 'none' and \
                re.match("(?:[^\n]*\n){%i}" % minlines, text):
            if self.paging == 'custom':
                self.custom_page_requested.emit(text)
            else:
                # disable buffer truncation during paging
                self._control.document().setMaximumBlockCount(0)
                self._page_control.clear()
                cursor = self._page_control.textCursor()
                if html:
                    self._insert_html(cursor, text)
                else:
                    self._insert_plain_text(cursor, text)
                self._page_control.moveCursor(QtGui.QTextCursor.Start)

                self._page_control.viewport().resize(self._control.size())
                if self._splitter:
                    self._page_control.show()
                    self._page_control.setFocus()
                else:
                    self.layout().setCurrentWidget(self._page_control)
        elif html:
            self._append_html(text)
        else:
            self._append_plain_text(text) 
開發者ID:jupyter,項目名稱:qtconsole,代碼行數:38,代碼來源:console_widget.py

示例9: set_min_size

# 需要導入模塊: from qtpy import QtGui [as 別名]
# 或者: from qtpy.QtGui import QFontMetrics [as 別名]
def set_min_size(self):
        """
        sets the min size for content to fit.
        """
        font = QtGui.QFont("", 0)
        font_metric = QtGui.QFontMetrics(font)
        pixel_wide = font_metric.width("0"*self.max_num_letter)
        self.line.setFixedWidth(pixel_wide) 
開發者ID:lneuhaus,項目名稱:pyrpl,代碼行數:10,代碼來源:spinbox.py


注:本文中的qtpy.QtGui.QFontMetrics方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。