本文整理汇总了Python中qtpy.QtGui.QFont方法的典型用法代码示例。如果您正苦于以下问题:Python QtGui.QFont方法的具体用法?Python QtGui.QFont怎么用?Python QtGui.QFont使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtGui
的用法示例。
在下文中一共展示了QtGui.QFont方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_plot_item
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QFont [as 别名]
def create_plot_item(self, name):
"""生成PlotItem对象"""
vb = CustomViewBox()
plotItem = pg.PlotItem(viewBox = vb, name=name ,axisItems={'bottom': self.axisTime})
plotItem.setMenuEnabled(False)
plotItem.setClipToView(True)
plotItem.hideAxis('left')
plotItem.showAxis('right')
plotItem.setDownsampling(mode='peak')
plotItem.setRange(xRange = (0,1),yRange = (0,1))
plotItem.getAxis('right').setWidth(60)
plotItem.getAxis('right').setStyle(tickFont = QtGui.QFont("Roman times",10,QtGui.QFont.Bold))
plotItem.getAxis('right').setPen(color=(255, 255, 255, 255), width=0.8)
plotItem.showGrid(True, True)
plotItem.hideButtons()
return plotItem
# ----------------------------------------------------------------------
示例2: data_internal
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QFont [as 别名]
def data_internal(self, index, record, role):
result = None
if role == Qt.DisplayRole:
if index.column() == self.columnCount(INVALID_INDEX) - 1:
result = record._cutelog
else:
column = self.table_header[index.column()]
if column.name == 'asctime':
result = record.asctime
elif role == Qt.SizeHintRole:
result = QSize(1, CONFIG.logger_row_height)
elif role == Qt.FontRole:
result = QFont(CONFIG.logger_table_font, CONFIG.logger_table_font_size)
elif role == Qt.ForegroundRole:
if not self.dark_theme:
result = QColor(Qt.black)
else:
result = QColor(Qt.white)
elif role == Qt.BackgroundRole:
if not self.dark_theme:
color = QColor(Qt.lightGray)
else:
color = QColor(Qt.darkGray)
result = QBrush(color, Qt.BDiagPattern)
return result
示例3: get_preview_items
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QFont [as 别名]
def get_preview_items(self, level):
previewItem = QTableWidgetItem("Log message")
previewItem.setBackground(QBrush(level.bg, Qt.SolidPattern))
previewItem.setForeground(QBrush(level.fg, Qt.SolidPattern))
previewItemDark = QTableWidgetItem("Log message")
previewItemDark.setBackground(QBrush(level.bgDark, Qt.SolidPattern))
previewItemDark.setForeground(QBrush(level.fgDark, Qt.SolidPattern))
font = QFont(CONFIG.logger_table_font, CONFIG.logger_table_font_size)
fontDark = QFont(font)
if 'bold' in level.styles:
font.setBold(True)
if 'italic' in level.styles:
font.setItalic(True)
if 'underline' in level.styles:
font.setUnderline(True)
if 'bold' in level.stylesDark:
fontDark.setBold(True)
if 'italic' in level.stylesDark:
fontDark.setItalic(True)
if 'underline' in level.stylesDark:
fontDark.setUnderline(True)
previewItem.setFont(font)
previewItemDark.setFont(fontDark)
return previewItem, previewItemDark
示例4: __init__
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QFont [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)
示例5: _resize_axis_labels
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QFont [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)
示例6: _resize_slice_labels
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QFont [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)
示例7: get_font
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QFont [as 别名]
def get_font(family, fallback=None):
"""Return a font of the requested family, using fallback as alternative.
If a fallback is provided, it is used in case the requested family isn't
found. If no fallback is given, no alternative is chosen and Qt's internal
algorithms may automatically choose a fallback font.
Parameters
----------
family : str
A font name.
fallback : str
A font name.
Returns
-------
font : QFont object
"""
font = QtGui.QFont(family)
# Check whether we got what we wanted using QFontInfo, since exactMatch()
# is overly strict and returns false in too many cases.
font_info = QtGui.QFontInfo(font)
if fallback is not None and font_info.family() != family:
font = QtGui.QFont(fallback)
return font
示例8: reset_font
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QFont [as 别名]
def reset_font(self):
""" Sets the font to the default fixed-width font for this platform.
"""
if sys.platform == 'win32':
# Consolas ships with Vista/Win7, fallback to Courier if needed
fallback = 'Courier'
elif sys.platform == 'darwin':
# OSX always has Monaco
fallback = 'Monaco'
else:
# Monospace should always exist
fallback = 'Monospace'
font = get_font(self.font_family, fallback)
if self.font_size:
font.setPointSize(self.font_size)
else:
font.setPointSize(QtWidgets.QApplication.instance().font().pointSize())
font.setStyleHint(QtGui.QFont.TypeWriter)
self._set_font(font)
示例9: __init__
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QFont [as 别名]
def __init__(self, xdict, *args, **kwargs):
pg.AxisItem.__init__(self, *args, **kwargs)
self.minVal = 0
self.maxVal = 0
# 序列 <= > 时间
self.xdict = OrderedDict()
self.xdict.update(xdict)
# 时间 <=> 序列
self.tdict = OrderedDict([(v,k) for k,v in xdict.items()])
self.x_values = np.asarray(xdict.keys())
self.x_strings = list(xdict.values())
self.setPen(color=(255, 255, 255, 255), width=0.8)
self.setStyle(tickFont = QtGui.QFont("Roman times",10,QtGui.QFont.Bold),autoExpandTextSpace=True)
示例10: convertMplWeightToQtWeight
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QFont [as 别名]
def convertMplWeightToQtWeight(self, weight: str) -> int:
""" convert a font weight string to a weight enumeration of Qt """
weight_dict = {'normal': QtGui.QFont.Normal, 'bold': QtGui.QFont.Bold, 'heavy': QtGui.QFont.ExtraBold,
'light': QtGui.QFont.Light, 'ultrabold': QtGui.QFont.Black, 'ultralight': QtGui.QFont.ExtraLight}
if weight in weight_dict:
return weight_dict[weight]
return weight_dict["normal"]
示例11: convertQtWeightToMplWeight
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QFont [as 别名]
def convertQtWeightToMplWeight(self, weight: int) -> str:
""" convert a Qt weight value to a string for use in matmplotlib """
weight_dict = {QtGui.QFont.Normal: 'normal', QtGui.QFont.Bold: 'bold', QtGui.QFont.ExtraBold: 'heavy',
QtGui.QFont.Light: 'light', QtGui.QFont.Black: 'ultrabold', QtGui.QFont.ExtraLight: 'ultralight'}
if weight in weight_dict:
return weight_dict[weight]
return "normal"
示例12: selectFont
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QFont [as 别名]
def selectFont(self):
""" open a font select dialog """
font0 = QtGui.QFont()
font0.setFamily(self.target.get_fontname())
font0.setWeight(self.convertMplWeightToQtWeight(self.target.get_weight()))
font0.setItalic(self.target.get_style() == "italic")
font0.setPointSizeF(self.target.get_fontsize())
font, x = QtWidgets.QFontDialog.getFont(font0, self)
for element in self.target_list:
element.set_fontname(font.family())
element.figure.change_tracker.addChange(element, ".set_fontname(\"%s\")" % (element.get_fontname(),))
if font.weight() != font0.weight():
weight = self.convertQtWeightToMplWeight(font.weight())
element.set_weight(weight)
element.figure.change_tracker.addChange(element, ".set_weight(\"%s\")" % (weight,))
if font.pointSizeF() != font0.pointSizeF():
element.set_fontsize(font.pointSizeF())
element.figure.change_tracker.addChange(element, ".set_fontsize(%f)" % (font.pointSizeF(),))
if font.italic() != font0.italic():
style = "italic" if font.italic() else "normal"
element.set_style(style)
element.figure.change_tracker.addChange(element, ".set_style(\"%s\")" % (style,))
self.target.figure.canvas.draw()
self.setTarget(self.target_list)
示例13: __init__
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QFont [as 别名]
def __init__(self, parent=None):
"""Constructor."""
QAbstractItemModel.__init__(self, parent)
self.abbreviator = Abbreviator()
self.is_dark_interface = False
self.testresults = []
try:
self.monospace_font = parent.window().editor.get_plugin_font()
except AttributeError: # If run standalone for testing
self.monospace_font = QFont("Courier New")
self.monospace_font.setPointSize(10)
示例14: reset
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QFont [as 别名]
def reset(self):
tlvcols = 4
tlvcolsnames = ['S', 'Pattern', 'P', 'Comment']
v = self.patternTable
v.setColumnCount(tlvcols)
lh = v.horizontalHeader()
lv = v.verticalHeader()
h = tlvcolsnames
n = len(h)
for i in range(n):
hi = QTableWidgetItem(h[i])
v.setHorizontalHeaderItem(i, hi)
for profkey in self._profiles:
prof = self._profiles[profkey]
for k in prof:
pentry = prof[k]
v.setRowCount(v.rowCount() + 1)
r = v.rowCount() - 1
it1 = QTableWidgetItem(self.IC(QW.I_EMPTY), '')
it2 = QTableWidgetItem(k)
it2.setFont(QFont("Courier"))
it3 = QTableWidgetItem(profkey)
it4 = QTableWidgetItem(pentry[2])
v.setItem(r, 0, it1)
v.setItem(r, 1, it2)
v.setItem(r, 2, it3)
v.setItem(r, 3, it4)
self.patternTable.resizeColumnsToContents()
self.patternTable.resizeRowsToContents()
plist = []
for i in range(len(plist)):
v.resizeColumnToContents(i)
for i in range(v.rowCount()):
v.resizeRowToContents(i)
self._initialized = True
示例15: addPathEntry
# 需要导入模块: from qtpy import QtGui [as 别名]
# 或者: from qtpy.QtGui import QFont [as 别名]
def addPathEntry(self, parent, path, state, top=False):
it = QTreeWidgetItem(parent, (path,))
ft = QFont(OCTXT._Table_Font)
if top:
ft.setBold(True)
it.setFont(0, ft)
if state == CGM.CHECK_FAIL:
it.setIcon(0, self.IC(QW.I_C_SFL))
if state == CGM.CHECK_WARN:
it.setIcon(0, self.IC(QW.I_C_SWR))
return it