本文整理汇总了Python中qtpy.QtWidgets.QLabel.setFont方法的典型用法代码示例。如果您正苦于以下问题:Python QLabel.setFont方法的具体用法?Python QLabel.setFont怎么用?Python QLabel.setFont使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QLabel
的用法示例。
在下文中一共展示了QLabel.setFont方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ReadWriteStatus
# 需要导入模块: from qtpy.QtWidgets import QLabel [as 别名]
# 或者: from qtpy.QtWidgets.QLabel import setFont [as 别名]
class ReadWriteStatus(StatusBarWidget):
"""Status bar widget for current file read/write mode."""
def __init__(self, parent, statusbar):
"""Status bar widget for current file read/write mode."""
super(ReadWriteStatus, self).__init__(parent, statusbar)
# Widget
self.label = QLabel(_("Permissions:"))
self.readwrite = QLabel()
# Widget setup
self.label.setAlignment(Qt.AlignRight)
self.readwrite.setFont(self.label_font)
# Layouts
layout = self.layout()
layout.addWidget(self.label)
layout.addWidget(self.readwrite)
layout.addSpacing(20)
def readonly_changed(self, readonly):
"""Update read/write file status."""
readwrite = "R" if readonly else "RW"
self.readwrite.setText(readwrite.ljust(3))
示例2: CursorPositionStatus
# 需要导入模块: from qtpy.QtWidgets import QLabel [as 别名]
# 或者: from qtpy.QtWidgets.QLabel import setFont [as 别名]
class CursorPositionStatus(StatusBarWidget):
"""Status bar widget for the current file cursor postion."""
def __init__(self, parent, statusbar):
"""Status bar widget for the current file cursor postion."""
super(CursorPositionStatus, self).__init__(parent, statusbar)
# Widget
self.label_line = QLabel(_("Line:"))
self.label_column = QLabel(_("Column:"))
self.column = QLabel()
self.line = QLabel()
# Widget setup
self.line.setFont(self.label_font)
self.column.setFont(self.label_font)
# Layout
layout = self.layout()
layout.addWidget(self.label_line)
layout.addWidget(self.line)
layout.addWidget(self.label_column)
layout.addWidget(self.column)
self.setLayout(layout)
def cursor_position_changed(self, line, index):
"""Update cursos position."""
self.line.setText("%-6d" % (line+1))
self.column.setText("%-4d" % (index+1))
示例3: EOLStatus
# 需要导入模块: from qtpy.QtWidgets import QLabel [as 别名]
# 或者: from qtpy.QtWidgets.QLabel import setFont [as 别名]
class EOLStatus(StatusBarWidget):
"""Status bar widget for the current file end of line."""
def __init__(self, parent, statusbar):
"""Status bar widget for the current file end of line."""
super(EOLStatus, self).__init__(parent, statusbar)
# Widget
self.label = QLabel(_("End-of-lines:"))
self.eol = QLabel()
# Widget setup
self.label.setAlignment(Qt.AlignRight)
self.eol.setFont(self.label_font)
# Layouts
layout = self.layout()
layout.addWidget(self.label)
layout.addWidget(self.eol)
layout.addSpacing(20)
def eol_changed(self, os_name):
"""Update end of line status."""
os_name = to_text_string(os_name)
self.eol.setText({"nt": "CRLF", "posix": "LF"}.get(os_name, "CR"))
示例4: EncodingStatus
# 需要导入模块: from qtpy.QtWidgets import QLabel [as 别名]
# 或者: from qtpy.QtWidgets.QLabel import setFont [as 别名]
class EncodingStatus(StatusBarWidget):
def __init__(self, parent, statusbar):
StatusBarWidget.__init__(self, parent, statusbar)
layout = self.layout()
layout.addWidget(QLabel(_("Encoding:")))
self.encoding = QLabel()
self.encoding.setFont(self.label_font)
layout.addWidget(self.encoding)
layout.addSpacing(20)
def encoding_changed(self, encoding):
self.encoding.setText(str(encoding).upper().ljust(15))
示例5: EOLStatus
# 需要导入模块: from qtpy.QtWidgets import QLabel [as 别名]
# 或者: from qtpy.QtWidgets.QLabel import setFont [as 别名]
class EOLStatus(StatusBarWidget):
def __init__(self, parent, statusbar):
StatusBarWidget.__init__(self, parent, statusbar)
layout = self.layout()
layout.addWidget(QLabel(_("End-of-lines:")))
self.eol = QLabel()
self.eol.setFont(self.label_font)
layout.addWidget(self.eol)
layout.addSpacing(20)
def eol_changed(self, os_name):
os_name = to_text_string(os_name)
self.eol.setText({"nt": "CRLF", "posix": "LF"}.get(os_name, "CR"))
示例6: ReadWriteStatus
# 需要导入模块: from qtpy.QtWidgets import QLabel [as 别名]
# 或者: from qtpy.QtWidgets.QLabel import setFont [as 别名]
class ReadWriteStatus(StatusBarWidget):
def __init__(self, parent, statusbar):
StatusBarWidget.__init__(self, parent, statusbar)
layout = self.layout()
layout.addWidget(QLabel(_("Permissions:")))
self.readwrite = QLabel()
self.readwrite.setFont(self.label_font)
layout.addWidget(self.readwrite)
layout.addSpacing(20)
def readonly_changed(self, readonly):
readwrite = "R" if readonly else "RW"
self.readwrite.setText(readwrite.ljust(3))
示例7: StatusBarWidget
# 需要导入模块: from qtpy.QtWidgets import QLabel [as 别名]
# 或者: from qtpy.QtWidgets.QLabel import setFont [as 别名]
class StatusBarWidget(QWidget):
"""Status bar widget base."""
TIP = None
def __init__(self, parent, statusbar, icon=None):
"""Status bar widget base."""
super(StatusBarWidget, self).__init__(parent)
# Variables
self.value = None
# Widget
self._icon = icon
self._pixmap = icon.pixmap(QSize(16, 16)) if icon is not None else None
self.label_icon = QLabel() if icon is not None else None
self.label_value = QLabel()
# Widget setup
if icon is not None:
self.label_icon.setPixmap(self._pixmap)
self.text_font = QFont(get_font(option='font')) # See Issue #9044
self.text_font.setPointSize(self.font().pointSize())
self.text_font.setBold(True)
self.label_value.setAlignment(Qt.AlignRight)
self.label_value.setFont(self.text_font)
if self.TIP:
self.setToolTip(self.TIP)
self.label_value.setToolTip(self.TIP)
# Layout
layout = QHBoxLayout()
if icon is not None:
layout.addWidget(self.label_icon)
layout.addWidget(self.label_value)
layout.addSpacing(20)
# Layout setup
layout.setContentsMargins(0, 0, 0, 0)
self.setLayout(layout)
# Setup
statusbar.addPermanentWidget(self)
def set_value(self, value):
"""Set formatted text value."""
self.value = value
if self.isVisible():
self.label_value.setText(value)
示例8: CursorPositionStatus
# 需要导入模块: from qtpy.QtWidgets import QLabel [as 别名]
# 或者: from qtpy.QtWidgets.QLabel import setFont [as 别名]
class CursorPositionStatus(StatusBarWidget):
def __init__(self, parent, statusbar):
StatusBarWidget.__init__(self, parent, statusbar)
layout = self.layout()
layout.addWidget(QLabel(_("Line:")))
self.line = QLabel()
self.line.setFont(self.label_font)
layout.addWidget(self.line)
layout.addWidget(QLabel(_("Column:")))
self.column = QLabel()
self.column.setFont(self.label_font)
layout.addWidget(self.column)
self.setLayout(layout)
def cursor_position_changed(self, line, index):
self.line.setText("%-6d" % (line+1))
self.column.setText("%-4d" % (index+1))
示例9: BaseTimerStatus
# 需要导入模块: from qtpy.QtWidgets import QLabel [as 别名]
# 或者: from qtpy.QtWidgets.QLabel import setFont [as 别名]
class BaseTimerStatus(StatusBarWidget):
TITLE = None
TIP = None
def __init__(self, parent, statusbar):
StatusBarWidget.__init__(self, parent, statusbar)
self.setToolTip(self.TIP)
layout = self.layout()
layout.addWidget(QLabel(self.TITLE))
self.label = QLabel()
self.label.setFont(self.label_font)
layout.addWidget(self.label)
layout.addSpacing(20)
if self.is_supported():
self.timer = QTimer()
self.timer.timeout.connect(self.update_label)
self.timer.start(2000)
else:
self.timer = None
self.hide()
def set_interval(self, interval):
"""Set timer interval (ms)"""
if self.timer is not None:
self.timer.setInterval(interval)
def import_test(self):
"""Raise ImportError if feature is not supported"""
raise NotImplementedError
def is_supported(self):
"""Return True if feature is supported"""
try:
self.import_test()
return True
except ImportError:
return False
def get_value(self):
"""Return value (e.g. CPU or memory usage)"""
raise NotImplementedError
def update_label(self):
"""Update status label widget, if widget is visible"""
if self.isVisible():
self.label.setText('%d %%' % self.get_value())
示例10: EncodingStatus
# 需要导入模块: from qtpy.QtWidgets import QLabel [as 别名]
# 或者: from qtpy.QtWidgets.QLabel import setFont [as 别名]
class EncodingStatus(StatusBarWidget):
"""Status bar widget for the current file encoding."""
def __init__(self, parent, statusbar):
"""Status bar widget for the current file encoding."""
super(EncodingStatus, self).__init__(parent, statusbar)
# Widgets
self.label = QLabel(_("Encoding:"))
self.encoding = QLabel()
# Widget setup
self.label.setAlignment(Qt.AlignRight)
self.encoding.setFont(self.label_font)
# Layouts
layout = self.layout()
layout.addWidget(self.label)
layout.addWidget(self.encoding)
layout.addSpacing(20)
def encoding_changed(self, encoding):
"""Update encoding of current file."""
self.encoding.setText(str(encoding).upper().ljust(15))
示例11: setup_page
# 需要导入模块: from qtpy.QtWidgets import QLabel [as 别名]
# 或者: from qtpy.QtWidgets.QLabel import setFont [as 别名]
def setup_page(self):
if ERR_MSG:
label = QLabel(_("Could not load plugin:\n{0}".format(ERR_MSG)))
layout = QVBoxLayout()
layout.addWidget(label)
self.setLayout(layout)
return
# Layout parameter
indent = QCheckBox().sizeHint().width()
# General options
options_group = QGroupBox(_("Options"))
# Hack : the spinbox widget will be added to self.spinboxes
spinboxes_before = set(self.spinboxes)
passes_spin = self.create_spinbox(
_("Number of pep8 passes: "), "", 'passes',
default=0, min_=0, max_=1000000, step=1)
spinbox = set(self.spinboxes) - spinboxes_before
spinbox = spinbox.pop()
spinbox.setSpecialValueText(_("Infinite"))
aggressive1_checkbox = self.create_checkbox(
"Aggressivity level 1", "aggressive1", default=False)
aggressive1_label = QLabel(_(
"Allow possibly unsafe fixes (E711 and W6), shorten lines"
" and remove trailing whitespace more aggressively (in"
" docstrings and multiline strings)."))
aggressive1_label.setWordWrap(True)
aggressive1_label.setIndent(indent)
font_description = aggressive1_label.font()
font_description.setPointSizeF(font_description.pointSize() * 0.9)
aggressive1_label.setFont(font_description)
aggressive2_checkbox = self.create_checkbox(
"Aggressivity level 2", "aggressive2", default=False)
aggressive2_label = QLabel(_(
"Allow more possibly unsafe fixes (E712) and shorten lines."))
aggressive2_label.setWordWrap(True)
aggressive2_label.setIndent(indent)
aggressive2_label.setFont(font_description)
aggressive1_checkbox.toggled.connect(
aggressive2_checkbox.setEnabled)
aggressive1_checkbox.toggled.connect(
aggressive2_label.setEnabled)
aggressive2_checkbox.setEnabled(aggressive1_checkbox.isChecked())
aggressive2_label.setEnabled(aggressive1_checkbox.isChecked())
# Enable/disable error codes
fix_layout = QVBoxLayout()
last_group = ""
FIX_LIST.sort(key=lambda item: item[0][1])
for code, description in FIX_LIST:
# Create a new group if necessary
if code[1] != last_group:
last_group = code[1]
group = QGroupBox(_(self.GROUPS.get(code[1], "")))
fix_layout.addWidget(group)
group_layout = QVBoxLayout(group)
# Checkbox for the option
text = code
default = True
if code in DEFAULT_IGNORE:
text += _(" (UNSAFE)")
default = False
option = self.create_checkbox(text, code, default=default)
# Label for description
if code in self.CODES:
label = QLabel("{autopep8} ({pep8}).".format(
autopep8=_(description).rstrip("."),
pep8=self.CODES[code]))
else:
label = QLabel(_(description))
label.setWordWrap(True)
label.setIndent(indent)
label.setFont(font_description)
# Add widgets to layout
option_layout = QVBoxLayout()
option_layout.setSpacing(0)
option_layout.addWidget(option)
option_layout.addWidget(label)
group_layout.addLayout(option_layout)
# Special cases
if code in ("E711", "W6"):
aggressive1_checkbox.toggled.connect(option.setEnabled)
aggressive1_checkbox.toggled.connect(label.setEnabled)
option.setEnabled(aggressive1_checkbox.isChecked())
label.setEnabled(aggressive1_checkbox.isChecked())
if code == "E712":
def e712_enabled():
enabled = (aggressive1_checkbox.isChecked()
and aggressive2_checkbox.isChecked())
option.setEnabled(enabled)
label.setEnabled(enabled)
aggressive1_checkbox.toggled.connect(e712_enabled)
aggressive2_checkbox.toggled.connect(e712_enabled)
e712_enabled()
#.........这里部分代码省略.........
示例12: BaseTimerStatus
# 需要导入模块: from qtpy.QtWidgets import QLabel [as 别名]
# 或者: from qtpy.QtWidgets.QLabel import setFont [as 别名]
class BaseTimerStatus(StatusBarWidget):
"""Status bar widget base for widgets that update based on timers."""
TITLE = None
TIP = None
def __init__(self, parent, statusbar):
"""Status bar widget base for widgets that update based on timers."""
super(BaseTimerStatus, self).__init__(parent, statusbar)
# Widgets
self.label = QLabel(self.TITLE)
self.value = QLabel()
# Widget setup
self.setToolTip(self.TIP)
self.value.setAlignment(Qt.AlignRight)
self.value.setFont(self.label_font)
fm = self.value.fontMetrics()
self.value.setMinimumWidth(fm.width('000%'))
# Layout
layout = self.layout()
layout.addWidget(self.label)
layout.addWidget(self.value)
layout.addSpacing(20)
# Setup
if self.is_supported():
self.timer = QTimer()
self.timer.timeout.connect(self.update_label)
self.timer.start(2000)
else:
self.timer = None
self.hide()
def set_interval(self, interval):
"""Set timer interval (ms)."""
if self.timer is not None:
self.timer.setInterval(interval)
def import_test(self):
"""Raise ImportError if feature is not supported."""
raise NotImplementedError
def is_supported(self):
"""Return True if feature is supported."""
try:
self.import_test()
return True
except ImportError:
return False
def get_value(self):
"""Return value (e.g. CPU or memory usage)."""
raise NotImplementedError
def update_label(self):
"""Update status label widget, if widget is visible."""
if self.isVisible():
self.value.setText('%d %%' % self.get_value())
示例13: __init__
# 需要导入模块: from qtpy.QtWidgets import QLabel [as 别名]
# 或者: from qtpy.QtWidgets.QLabel import setFont [as 别名]
def __init__(self, parent=None):
QDialog.__init__(self, parent=parent)
self._shortcuts_summary_title = _("Spyder Keyboard ShortCuts")
# Calculate font and amount of elements in each column according screen size
width, height = self.get_screen_resolution()
font_size = height / 80
font_size = max(min(font_size, MAX_FONT_SIZE), MIN_FONT_SIZE)
shortcuts_column = (height - 8 * font_size) / (font_size +16)
# Widgets
style = """
QDialog {
margin:0px;
padding:0px;
border-radius: 2px;
}"""
self.setStyleSheet(style)
font_names = QFont()
font_names.setPointSize(font_size)
font_names.setBold(True)
font_keystr = QFont()
font_keystr.setPointSize(font_size)
font_title = QFont()
font_title.setPointSize(font_size+2)
font_title.setBold(True)
title_label = QLabel(self._shortcuts_summary_title)
title_label.setAlignment(Qt.AlignCenter)
title_label.setFont(font_title)
# iter over shortcuts and create GroupBox for each context
# with shortcuts in a grid
columns_layout = QHBoxLayout()
added_shortcuts = 0
group = None
# group shortcuts by context
shortcuts = groupby(sorted(iter_shortcuts()), key=itemgetter(0))
for context, group_shortcuts in shortcuts:
for i, (context, name, keystr) in enumerate(group_shortcuts):
# start of every column
if added_shortcuts == 0:
column_layout = QVBoxLayout()
# at start of new context add previous context group
if i == 0 and added_shortcuts > 0:
column_layout.addWidget(group)
# create group at start of column or context
if added_shortcuts == 0 or i == 0:
if context == '_': context = 'Global'
group = QGroupBox(context.capitalize())
group.setFont(font_names)
group_layout = QGridLayout()
group.setLayout(group_layout)
# Count space for titles
added_shortcuts += 1
# Widgets
label_name = QLabel(name.capitalize().replace('_', ' '))
label_name.setFont(font_names)
keystr = QKeySequence(keystr).toString(QKeySequence.NativeText)
label_keystr = QLabel(keystr)
label_keystr.setFont(font_keystr)
group_layout.addWidget(label_name, i, 0)
group_layout.addWidget(label_keystr, i, 1)
added_shortcuts += 1
if added_shortcuts >= shortcuts_column:
column_layout.addWidget(group)
columns_layout.addLayout(column_layout)
added_shortcuts = 0
column_layout.addWidget(group)
column_layout.addStretch() # avoid lasts sections to appear too big
columns_layout.addLayout(column_layout)
# Scroll widget
self.scroll_widget = QWidget()
self.scroll_widget.setLayout(columns_layout)
self.scroll_area = QScrollArea()
self.scroll_area.setWidget(self.scroll_widget)
# widget setup
self.setWindowFlags(Qt.FramelessWindowHint)
self.setWindowOpacity(0.95)
# layout
#.........这里部分代码省略.........
示例14: MomentMapsGUI
# 需要导入模块: from qtpy.QtWidgets import QLabel [as 别名]
# 或者: from qtpy.QtWidgets.QLabel import setFont [as 别名]
class MomentMapsGUI(QDialog):
def __init__(self, data, data_collection, parent=None):
super(MomentMapsGUI, self).__init__(parent)
# Get the data_components (e.g., FLUX, DQ, ERROR etc)
# Using list comprehension to keep the order of the component_ids
self.data_components = [str(x).strip() for x in data.component_ids() if not x in data.coordinate_components]
self.data = data
self.data_collection = data_collection
self.parent = parent
self.label = ''
self.calculateButton = None
self.cancelButton = None
def display(self):
"""
Create the popup box with the calculation input area and buttons.
:return:
"""
self.setWindowFlags(self.windowFlags() | Qt.Tool)
self.setWindowTitle("Create Moment Map")
boldFont = QtGui.QFont()
boldFont.setBold(True)
# Create calculation label and input box
self.data_label = QLabel("Data:")
self.data_label.setFixedWidth(100)
self.data_label.setAlignment((Qt.AlignRight | Qt.AlignTop))
self.data_label.setFont(boldFont)
self.data_combobox = QComboBox()
self.data_combobox.addItems([str(x).strip() for x in self.data.component_ids() if not x in self.data.coordinate_components])
self.data_combobox.setMinimumWidth(200)
hbl1 = QHBoxLayout()
hbl1.addWidget(self.data_label)
hbl1.addWidget(self.data_combobox)
# Create calculation label and input box
self.order_label = QLabel("Order:")
self.order_label.setFixedWidth(100)
self.order_label.setAlignment((Qt.AlignRight | Qt.AlignTop))
self.order_label.setFont(boldFont)
self.order_combobox = QComboBox()
self.order_combobox.addItems(["1", "2", "3", "4", "5", "6", "7", "8"])
self.order_combobox.setMinimumWidth(200)
hbl2 = QHBoxLayout()
hbl2.addWidget(self.order_label)
hbl2.addWidget(self.order_combobox)
# Create Calculate and Cancel buttons
self.calculateButton = QPushButton("Calculate")
self.calculateButton.clicked.connect(self.calculate_callback)
self.calculateButton.setDefault(True)
self.cancelButton = QPushButton("Cancel")
self.cancelButton.clicked.connect(self.cancel_callback)
hbl5 = QHBoxLayout()
hbl5.addStretch(1)
hbl5.addWidget(self.cancelButton)
hbl5.addWidget(self.calculateButton)
# Add calculation and buttons to popup box
vbl = QVBoxLayout()
vbl.addLayout(hbl1)
vbl.addLayout(hbl2)
vbl.addLayout(hbl5)
self.setLayout(vbl)
self.setMaximumWidth(700)
self.show()
def do_calculation(self, order, data_name):
# Grab spectral-cube
import spectral_cube
cube = spectral_cube.SpectralCube(self.data[data_name], wcs=self.data.coords.wcs)
cube_moment = cube.moment(order=order, axis=0)
self.label = '{}-moment-{}'.format(data_name, order)
# Add new overlay/component to cubeviz. We add this both to the 2D
# container Data object and also as an overlay. In future we might be
# able to use the 2D container Data object for the overlays directly.
add_to_2d_container(self.parent, self.data, cube_moment.value, cube_moment.unit, self.label)
# Going to pass in just the value into the overlay as the units aren't
# currently used for the overlay area. BUT, this is probably not the
# best way to do this.
self.parent.add_overlay(cube_moment.value, self.label, display_now=False)
def calculate_callback(self):
#.........这里部分代码省略.........