本文整理汇总了Python中guidata.qt.QtGui.QLabel类的典型用法代码示例。如果您正苦于以下问题:Python QLabel类的具体用法?Python QLabel怎么用?Python QLabel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QLabel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, parent, new_size, old_size, text="", keep_original_size=False):
QDialog.__init__(self, parent)
intfunc = lambda tup: [int(val) for val in tup]
if intfunc(new_size) == intfunc(old_size):
self.keep_original_size = True
else:
self.keep_original_size = keep_original_size
self.width, self.height = new_size
self.old_width, self.old_height = old_size
self.ratio = self.width / self.height
layout = QVBoxLayout()
self.setLayout(layout)
formlayout = QFormLayout()
layout.addLayout(formlayout)
if text:
label = QLabel(text)
label.setAlignment(Qt.AlignHCenter)
formlayout.addRow(label)
self.w_edit = w_edit = QLineEdit(self)
w_valid = QIntValidator(w_edit)
w_valid.setBottom(1)
w_edit.setValidator(w_valid)
self.h_edit = h_edit = QLineEdit(self)
h_valid = QIntValidator(h_edit)
h_valid.setBottom(1)
h_edit.setValidator(h_valid)
zbox = QCheckBox(_("Original size"), self)
formlayout.addRow(_("Width (pixels)"), w_edit)
formlayout.addRow(_("Height (pixels)"), h_edit)
formlayout.addRow("", zbox)
formlayout.addRow(_("Original size:"), QLabel("%d x %d" % old_size))
self.z_label = QLabel()
formlayout.addRow(_("Zoom factor:"), self.z_label)
# Button box
self.bbox = bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
bbox.accepted.connect(self.accept)
bbox.rejected.connect(self.reject)
layout.addWidget(bbox)
self.w_edit.setText(str(self.width))
self.h_edit.setText(str(self.height))
self.update_widgets()
self.setWindowTitle(_("Resize"))
w_edit.textChanged.connect(self.width_changed)
h_edit.textChanged.connect(self.height_changed)
zbox.toggled.connect(self.toggled_no_zoom)
zbox.setChecked(self.keep_original_size)
示例2: __init__
def __init__(self, parent, new_size, old_size, text=""):
QDialog.__init__(self, parent)
self.keep_original_size = False
self.width, self.height = new_size
self.old_width, self.old_height = old_size
self.ratio = self.width/self.height
layout = QVBoxLayout()
self.setLayout(layout)
formlayout = QFormLayout()
layout.addLayout(formlayout)
if text:
label = QLabel(text)
label.setAlignment(Qt.AlignHCenter)
formlayout.addRow(label)
self.w_edit = w_edit = QLineEdit(self)
w_valid = QIntValidator(w_edit)
w_valid.setBottom(1)
w_edit.setValidator(w_valid)
self.h_edit = h_edit = QLineEdit(self)
h_valid = QIntValidator(h_edit)
h_valid.setBottom(1)
h_edit.setValidator(h_valid)
zbox = QCheckBox(_("Original size"), self)
formlayout.addRow(_("Width (pixels)"), w_edit)
formlayout.addRow(_("Height (pixels)"), h_edit)
formlayout.addRow('', zbox)
formlayout.addRow(_("Original size:"), QLabel("%d x %d" % old_size))
self.z_label = QLabel()
formlayout.addRow(_("Zoom factor:"), self.z_label)
# Button box
self.bbox = bbox = QDialogButtonBox(QDialogButtonBox.Ok|
QDialogButtonBox.Cancel)
self.connect(bbox, SIGNAL("accepted()"), SLOT("accept()"))
self.connect(bbox, SIGNAL("rejected()"), SLOT("reject()"))
layout.addWidget(bbox)
self.w_edit.setText(str(self.width))
self.h_edit.setText(str(self.height))
self.update_widgets()
self.setWindowTitle(_("Resize"))
self.connect(w_edit, SIGNAL("textChanged(QString)"),
self.width_changed)
self.connect(h_edit, SIGNAL("textChanged(QString)"),
self.height_changed)
self.connect(zbox, SIGNAL("toggled(bool)"), self.toggled_no_zoom)
示例3: get_image_label
def get_image_label(name, default="not_found.png"):
"""
Construct a QLabel from the file with specified name
name, default: filenames with extensions
"""
label = QLabel()
pixmap = QPixmap(get_image_file_path(name, default))
label.setPixmap(pixmap)
return label
示例4: __init__
def __init__(self, parent):
QWidget.__init__(self, parent)
font = QFont(get_family(MONOSPACE), 10, QFont.Normal)
info_icon = QLabel()
icon = get_std_icon("MessageBoxInformation").pixmap(24, 24)
info_icon.setPixmap(icon)
info_icon.setFixedWidth(32)
info_icon.setAlignment(Qt.AlignTop)
self.service_status_label = QLabel()
self.service_status_label.setWordWrap(True)
self.service_status_label.setAlignment(Qt.AlignTop)
self.service_status_label.setFont(font)
self.desc_label = QLabel()
self.desc_label.setWordWrap(True)
self.desc_label.setAlignment(Qt.AlignTop)
self.desc_label.setFont(font)
self.group_desc = QGroupBox("Description", self)
layout = QHBoxLayout()
layout.addWidget(info_icon)
layout.addWidget(self.desc_label)
layout.addStretch()
layout.addWidget(self.service_status_label)
self.group_desc.setLayout(layout)
self.editor = CodeEditor(self)
self.editor.setup_editor(linenumbers=True, font=font)
self.editor.setReadOnly(False)
self.group_code = QGroupBox("Source code", self)
layout = QVBoxLayout()
layout.addWidget(self.editor)
self.group_code.setLayout(layout)
self.enable_button = QPushButton(get_icon("apply.png"), "Enable", self)
self.save_button = QPushButton(get_icon("filesave.png"), "Save", self)
self.disable_button = QPushButton(get_icon("delete.png"), "Disable", self)
self.refresh_button = QPushButton(get_icon("restart.png"), "Refresh", self)
hlayout = QHBoxLayout()
hlayout.addWidget(self.save_button)
hlayout.addWidget(self.enable_button)
hlayout.addWidget(self.disable_button)
hlayout.addWidget(self.refresh_button)
vlayout = QVBoxLayout()
vlayout.addWidget(self.group_desc)
vlayout.addWidget(self.group_code)
self.html_window = HTMLWindow()
vlayout.addWidget(self.html_window)
vlayout.addLayout(hlayout)
self.setLayout(vlayout)
self.current_file = None
示例5: __init__
def __init__(self, text, parent=None, angle=270,
family=None, bold=False, italic=False, color=None):
QLabel.__init__(self, text, parent)
font = self.font()
if family is not None:
font.setFamily(get_family(family))
font.setBold(bold)
font.setItalic(italic)
self.setFont(font)
self.color = color
self.angle = angle
self.setAlignment(Qt.AlignCenter)
示例6: __init__
def __init__(self, label, klass, wordwrap=False, **kwargs):
QGroupBox.__init__(self, label)
self.klass = klass
self.dataset = klass(**kwargs)
self.layout = QVBoxLayout()
if self.dataset.get_comment():
label = QLabel(self.dataset.get_comment())
label.setWordWrap(wordwrap)
self.layout.addWidget(label)
self.grid_layout = QGridLayout()
self.layout.addLayout(self.grid_layout)
self.setLayout(self.layout)
self.edit = self.get_edit_layout()
示例7: get_image_layout
def get_image_layout(imagename, text="", tooltip="", alignment=Qt.AlignLeft):
"""
Construct a QHBoxLayout including image from the file with specified name,
left-aligned text [with specified tooltip]
Return (layout, label)
"""
layout = QHBoxLayout()
if alignment in (Qt.AlignCenter, Qt.AlignRight):
layout.addStretch()
layout.addWidget(get_image_label(imagename))
label = QLabel(text)
label.setToolTip(tooltip)
layout.addWidget(label)
if alignment in (Qt.AlignCenter, Qt.AlignLeft):
layout.addStretch()
return (layout, label)
示例8: sizeHint
def sizeHint(self):
hint = QLabel.sizeHint(self)
width, height = hint.width(), hint.height()
angle = self.angle*pi/180
rotated_width = abs(width*cos(angle))+abs(height*sin(angle))
rotated_height = abs(width*sin(angle))+abs(height*cos(angle))
return QSize(rotated_width, rotated_height)
示例9: place_label
def place_label(self, layout, row, column):
"""
Place item label on layout at specified position (row, column)
"""
label_text = self.item.get_prop_value("display", "label")
unit = self.item.get_prop_value("display", "unit", '')
if unit and not self.READ_ONLY:
label_text += (' (%s)' % unit)
self.label = QLabel(label_text)
self.label.setToolTip(self.item.get_help())
layout.addWidget(self.label, row, column)
示例10: create_widgets
def create_widgets(self, parent, refresh_callback):
self._refresh_callback = refresh_callback
self.prefix_label = QLabel()
font = self.prefix_label.font()
font.setPointSize(font.pointSize()+self._size_offset)
self.prefix_label.setFont(font)
self.button = QPushButton()
self.button.setIcon(get_icon('settings.png'))
self.button.setToolTip(
_("Edit '%s' fit parameter properties") % self.name)
self.button.clicked.connect(lambda: self.edit_param(parent))
self.lineedit = QLineEdit()
self.lineedit.editingFinished.connect(self.line_editing_finished)
self.unit_label = QLabel(self.unit)
self.slider = QSlider()
self.slider.setOrientation(Qt.Horizontal)
self.slider.setRange(0, self.steps-1)
self.slider.valueChanged.connect(self.slider_value_changed)
self.update(refresh=False)
self.add_widgets([self.prefix_label, self.lineedit, self.unit_label,
self.slider, self.button])
示例11: DataSetShowWidget
class DataSetShowWidget(AbstractDataSetWidget):
"""Read-only base widget"""
READ_ONLY = True
def __init__(self, item, parent_layout):
AbstractDataSetWidget.__init__(self, item, parent_layout)
self.group = QLabel()
wordwrap = item.get_prop_value("display", "wordwrap", False)
self.group.setWordWrap(wordwrap)
self.group.setToolTip(item.get_help())
self.group.setStyleSheet( LABEL_CSS )
self.group.setTextInteractionFlags(Qt.TextSelectableByMouse)
#self.group.setEnabled(False)
def get(self):
"""Override AbstractDataSetWidget method"""
self.set_state()
text = self.item.get_string_value()
self.group.setText(text)
def set(self):
"""Read only..."""
pass
示例12: __init__
def __init__(self, parent):
QWidget.__init__(self, parent)
layout = QHBoxLayout()
row_nb = 14
cindex = 0
for child in dir(QStyle):
if child.startswith('SP_'):
if cindex == 0:
col_layout = QVBoxLayout()
icon_layout = QHBoxLayout()
icon = get_std_icon(child)
label = QLabel()
label.setPixmap(icon.pixmap(32, 32))
icon_layout.addWidget( label )
icon_layout.addWidget( QLineEdit(child.replace('SP_', '')) )
col_layout.addLayout(icon_layout)
cindex = (cindex+1) % row_nb
if cindex == 0:
layout.addLayout(col_layout)
self.setLayout(layout)
self.setWindowTitle('Standard Platform Icons')
self.setWindowIcon(get_std_icon('TitleBarMenuButton'))
示例13: setup_instance
def setup_instance(self, instance):
"""Override DataSetEditDialog method"""
from guidata.dataset.datatypes import DataSetGroup
assert isinstance(instance, DataSetGroup)
tabs = QTabWidget()
# tabs.setUsesScrollButtons(False)
self.layout.addWidget(tabs)
for dataset in instance.datasets:
layout = QVBoxLayout()
layout.setAlignment(Qt.AlignTop)
if dataset.get_comment():
label = QLabel(dataset.get_comment())
label.setWordWrap(self.wordwrap)
layout.addWidget(label)
grid = QGridLayout()
self.edit_layout.append( self.layout_factory(dataset, grid) )
layout.addLayout(grid)
page = QWidget()
page.setLayout(layout)
if dataset.get_icon():
tabs.addTab( page, get_icon(dataset.get_icon()),
dataset.get_title() )
else:
tabs.addTab( page, dataset.get_title() )
示例14: TestPropertiesWidget
class TestPropertiesWidget(QWidget):
def __init__(self, parent):
QWidget.__init__(self, parent)
font = QFont(get_family(MONOSPACE), 10, QFont.Normal)
info_icon = QLabel()
icon = get_std_icon('MessageBoxInformation').pixmap(24, 24)
info_icon.setPixmap(icon)
info_icon.setFixedWidth(32)
info_icon.setAlignment(Qt.AlignTop)
self.desc_label = QLabel()
self.desc_label.setWordWrap(True)
self.desc_label.setAlignment(Qt.AlignTop)
self.desc_label.setFont(font)
group_desc = QGroupBox(_("Description"), self)
layout = QHBoxLayout()
layout.addWidget(info_icon)
layout.addWidget(self.desc_label)
group_desc.setLayout(layout)
self.editor = CodeEditor(self)
self.editor.setup_editor(linenumbers=True, font=font)
self.editor.setReadOnly(True)
group_code = QGroupBox(_("Source code"), self)
layout = QVBoxLayout()
layout.addWidget(self.editor)
group_code.setLayout(layout)
self.run_button = QPushButton(get_icon("apply.png"),
_("Run this script"), self)
self.quit_button = QPushButton(get_icon("exit.png"), _("Quit"), self)
hlayout = QHBoxLayout()
hlayout.addWidget(self.run_button)
hlayout.addStretch()
hlayout.addWidget(self.quit_button)
vlayout = QVBoxLayout()
vlayout.addWidget(group_desc)
vlayout.addWidget(group_code)
vlayout.addLayout(hlayout)
self.setLayout(vlayout)
def set_item(self, test):
self.desc_label.setText(test.get_description())
self.editor.set_text_from_file(test.filename)
示例15: FitParam
class FitParam(object):
def __init__(self, name, value, min, max, logscale=False,
steps=5000, format='%.3f', size_offset=0, unit=''):
self.name = name
self.value = value
self.min = min
self.max = max
self.logscale = logscale
self.steps = steps
self.format = format
self.unit = unit
self.prefix_label = None
self.lineedit = None
self.unit_label = None
self.slider = None
self.button = None
self._widgets = []
self._size_offset = size_offset
self._refresh_callback = None
self.dataset = FitParamDataSet(title=_("Curve fitting parameter"))
def copy(self):
"""Return a copy of this fitparam"""
return self.__class__(self.name, self.value, self.min, self.max,
self.logscale, self.steps, self.format,
self._size_offset, self.unit)
def create_widgets(self, parent, refresh_callback):
self._refresh_callback = refresh_callback
self.prefix_label = QLabel()
font = self.prefix_label.font()
font.setPointSize(font.pointSize()+self._size_offset)
self.prefix_label.setFont(font)
self.button = QPushButton()
self.button.setIcon(get_icon('settings.png'))
self.button.setToolTip(
_("Edit '%s' fit parameter properties") % self.name)
self.button.clicked.connect(lambda: self.edit_param(parent))
self.lineedit = QLineEdit()
self.lineedit.editingFinished.connect(self.line_editing_finished)
self.unit_label = QLabel(self.unit)
self.slider = QSlider()
self.slider.setOrientation(Qt.Horizontal)
self.slider.setRange(0, self.steps-1)
self.slider.valueChanged.connect(self.slider_value_changed)
self.update(refresh=False)
self.add_widgets([self.prefix_label, self.lineedit, self.unit_label,
self.slider, self.button])
def add_widgets(self, widgets):
self._widgets += widgets
def get_widgets(self):
return self._widgets
def set_scale(self, state):
self.logscale = state > 0
self.update_slider_value()
def set_text(self, fmt=None):
style = "<span style=\'color: #444444\'><b>%s</b></span>"
self.prefix_label.setText(style % self.name)
if self.value is None:
value_str = ''
else:
if fmt is None:
fmt = self.format
value_str = fmt % self.value
self.lineedit.setText(value_str)
self.lineedit.setDisabled(
self.value == self.min and self.max == self.min)
def line_editing_finished(self):
try:
self.value = float(self.lineedit.text())
except ValueError:
self.set_text()
self.update_slider_value()
self._refresh_callback()
def slider_value_changed(self, int_value):
if self.logscale:
total_delta = np.log10(1+self.max-self.min)
self.value = self.min+10**(total_delta*int_value/(self.steps-1))-1
else:
total_delta = self.max-self.min
self.value = self.min+total_delta*int_value/(self.steps-1)
self.set_text()
self._refresh_callback()
def update_slider_value(self):
if (self.value is None or self.min is None or self.max is None):
self.slider.setEnabled(False)
if self.slider.parent() and self.slider.parent().isVisible():
self.slider.show()
elif self.value == self.min and self.max == self.min:
self.slider.hide()
else:
self.slider.setEnabled(True)
if self.slider.parent() and self.slider.parent().isVisible():
#.........这里部分代码省略.........