本文整理汇总了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)
示例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)
示例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)
示例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)
示例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
#---------------------------------------------------------------------------
示例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)
示例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
示例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)
示例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)