本文整理汇总了Python中AnyQt.QtWidgets.QLabel.setSizePolicy方法的典型用法代码示例。如果您正苦于以下问题:Python QLabel.setSizePolicy方法的具体用法?Python QLabel.setSizePolicy怎么用?Python QLabel.setSizePolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QLabel
的用法示例。
在下文中一共展示了QLabel.setSizePolicy方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DummyOWWidget
# 需要导入模块: from AnyQt.QtWidgets import QLabel [as 别名]
# 或者: from AnyQt.QtWidgets.QLabel import setSizePolicy [as 别名]
class DummyOWWidget(widget.OWWidget):
"""
Dummy OWWidget used to report import/init errors in the canvas.
"""
name = "Placeholder"
# Fake settings handler that preserves the settings
class DummySettingsHandler(settings.SettingsHandler):
def pack_data(self, widget):
return getattr(widget, "_settings", {})
def initialize(self, widget, data=None):
widget._settings = data
settings.SettingsHandler.initialize(self, widget, None)
# specifically disable persistent global defaults
def write_defaults(self):
pass
def read_defaults(self):
pass
settingsHandler = DummySettingsHandler()
want_main_area = False
def __init__(self, parent=None):
super().__init__(parent)
self.errorLabel = QLabel(
textInteractionFlags=Qt.TextSelectableByMouse,
wordWrap=True,
)
self.errorLabel.setSizePolicy(
QSizePolicy.Expanding,
QSizePolicy.Expanding
)
self.controlArea.layout().addWidget(self.errorLabel)
def setErrorMessage(self, message):
self.errorLabel.setText(message)
self.error(message)
示例2: OWFile
# 需要导入模块: from AnyQt.QtWidgets import QLabel [as 别名]
# 或者: from AnyQt.QtWidgets.QLabel import setSizePolicy [as 别名]
class OWFile(widget.OWWidget, RecentPathsWComboMixin):
name = "File"
id = "orange.widgets.data.file"
description = "Read data from an input file or network " \
"and send a data table to the output."
icon = "icons/File.svg"
priority = 10
category = "Data"
keywords = ["file", "load", "read", "open"]
class Outputs:
data = Output("Data", Table,
doc="Attribute-valued dataset read from the input file.")
want_main_area = False
SEARCH_PATHS = [("sample-datasets", get_sample_datasets_dir())]
SIZE_LIMIT = 1e7
LOCAL_FILE, URL = range(2)
settingsHandler = PerfectDomainContextHandler(
match_values=PerfectDomainContextHandler.MATCH_VALUES_ALL
)
# pylint seems to want declarations separated from definitions
recent_paths: List[RecentPath]
recent_urls: List[str]
variables: list
# Overload RecentPathsWidgetMixin.recent_paths to set defaults
recent_paths = Setting([
RecentPath("", "sample-datasets", "iris.tab"),
RecentPath("", "sample-datasets", "titanic.tab"),
RecentPath("", "sample-datasets", "housing.tab"),
RecentPath("", "sample-datasets", "heart_disease.tab"),
])
recent_urls = Setting([])
source = Setting(LOCAL_FILE)
xls_sheet = ContextSetting("")
sheet_names = Setting({})
url = Setting("")
variables = ContextSetting([])
domain_editor = SettingProvider(DomainEditor)
class Warning(widget.OWWidget.Warning):
file_too_big = widget.Msg("The file is too large to load automatically."
" Press Reload to load.")
load_warning = widget.Msg("Read warning:\n{}")
class Error(widget.OWWidget.Error):
file_not_found = widget.Msg("File not found.")
missing_reader = widget.Msg("Missing reader.")
sheet_error = widget.Msg("Error listing available sheets.")
unknown = widget.Msg("Read error:\n{}")
class NoFileSelected:
pass
def __init__(self):
super().__init__()
RecentPathsWComboMixin.__init__(self)
self.domain = None
self.data = None
self.loaded_file = ""
self.reader = None
layout = QGridLayout()
gui.widgetBox(self.controlArea, margin=0, orientation=layout)
vbox = gui.radioButtons(None, self, "source", box=True, addSpace=True,
callback=self.load_data, addToLayout=False)
rb_button = gui.appendRadioButton(vbox, "File:", addToLayout=False)
layout.addWidget(rb_button, 0, 0, Qt.AlignVCenter)
box = gui.hBox(None, addToLayout=False, margin=0)
box.setSizePolicy(Policy.MinimumExpanding, Policy.Fixed)
self.file_combo.setSizePolicy(Policy.MinimumExpanding, Policy.Fixed)
self.file_combo.activated[int].connect(self.select_file)
box.layout().addWidget(self.file_combo)
layout.addWidget(box, 0, 1)
file_button = gui.button(
None, self, '...', callback=self.browse_file, autoDefault=False)
file_button.setIcon(self.style().standardIcon(QStyle.SP_DirOpenIcon))
file_button.setSizePolicy(Policy.Maximum, Policy.Fixed)
layout.addWidget(file_button, 0, 2)
reload_button = gui.button(
None, self, "Reload", callback=self.load_data, autoDefault=False)
reload_button.setIcon(self.style().standardIcon(
QStyle.SP_BrowserReload))
reload_button.setSizePolicy(Policy.Fixed, Policy.Fixed)
layout.addWidget(reload_button, 0, 3)
self.sheet_box = gui.hBox(None, addToLayout=False, margin=0)
self.sheet_combo = gui.comboBox(None, self, "xls_sheet",
callback=self.select_sheet,
sendSelectedValue=True,)
#.........这里部分代码省略.........
示例3: OWFile
# 需要导入模块: from AnyQt.QtWidgets import QLabel [as 别名]
# 或者: from AnyQt.QtWidgets.QLabel import setSizePolicy [as 别名]
class OWFile(widget.OWWidget, RecentPathsWComboMixin):
name = "File"
id = "orange.widgets.data.file"
description = "Read data from an input file or network " \
"and send a data table to the output."
icon = "icons/File.svg"
priority = 10
category = "Data"
keywords = ["data", "file", "load", "read"]
outputs = [widget.OutputSignal(
"Data", Table,
doc="Attribute-valued data set read from the input file.")]
want_main_area = False
SEARCH_PATHS = [("sample-datasets", get_sample_datasets_dir())]
SIZE_LIMIT = 1e7
LOCAL_FILE, URL = range(2)
settingsHandler = PerfectDomainContextHandler()
# Overload RecentPathsWidgetMixin.recent_paths to set defaults
recent_paths = Setting([
RecentPath("", "sample-datasets", "iris.tab"),
RecentPath("", "sample-datasets", "titanic.tab"),
RecentPath("", "sample-datasets", "housing.tab"),
RecentPath("", "sample-datasets", "heart_disease.tab"),
])
recent_urls = Setting([])
source = Setting(LOCAL_FILE)
xls_sheet = ContextSetting("")
sheet_names = Setting({})
url = Setting("")
variables = ContextSetting([])
dlg_formats = (
"All readable files ({});;".format(
'*' + ' *'.join(FileFormat.readers.keys())) +
";;".join("{} (*{})".format(f.DESCRIPTION, ' *'.join(f.EXTENSIONS))
for f in sorted(set(FileFormat.readers.values()),
key=list(FileFormat.readers.values()).index)))
class Warning(widget.OWWidget.Warning):
file_too_big = widget.Msg("The file is too large to load automatically."
" Press Reload to load.")
def __init__(self):
super().__init__()
RecentPathsWComboMixin.__init__(self)
self.domain = None
self.data = None
self.loaded_file = ""
self.reader = None
layout = QGridLayout()
gui.widgetBox(self.controlArea, margin=0, orientation=layout)
vbox = gui.radioButtons(None, self, "source", box=True, addSpace=True,
callback=self.load_data, addToLayout=False)
rb_button = gui.appendRadioButton(vbox, "File:", addToLayout=False)
layout.addWidget(rb_button, 0, 0, Qt.AlignVCenter)
box = gui.hBox(None, addToLayout=False, margin=0)
box.setSizePolicy(Policy.MinimumExpanding, Policy.Fixed)
self.file_combo.setSizePolicy(Policy.MinimumExpanding, Policy.Fixed)
self.file_combo.activated[int].connect(self.select_file)
box.layout().addWidget(self.file_combo)
layout.addWidget(box, 0, 1)
file_button = gui.button(
None, self, '...', callback=self.browse_file, autoDefault=False)
file_button.setIcon(self.style().standardIcon(QStyle.SP_DirOpenIcon))
file_button.setSizePolicy(Policy.Maximum, Policy.Fixed)
layout.addWidget(file_button, 0, 2)
reload_button = gui.button(
None, self, "Reload", callback=self.load_data, autoDefault=False)
reload_button.setIcon(self.style().standardIcon(
QStyle.SP_BrowserReload))
reload_button.setSizePolicy(Policy.Fixed, Policy.Fixed)
layout.addWidget(reload_button, 0, 3)
self.sheet_box = gui.hBox(None, addToLayout=False, margin=0)
self.sheet_combo = gui.comboBox(None, self, "xls_sheet",
callback=self.select_sheet,
sendSelectedValue=True)
self.sheet_combo.setSizePolicy(
Policy.MinimumExpanding, Policy.Fixed)
self.sheet_label = QLabel()
self.sheet_label.setText('Sheet')
self.sheet_label.setSizePolicy(
Policy.MinimumExpanding, Policy.Fixed)
self.sheet_box.layout().addWidget(
self.sheet_label, Qt.AlignLeft)
self.sheet_box.layout().addWidget(
self.sheet_combo, Qt.AlignVCenter)
layout.addWidget(self.sheet_box, 2, 1)
self.sheet_box.hide()
#.........这里部分代码省略.........
示例4: __init__
# 需要导入模块: from AnyQt.QtWidgets import QLabel [as 别名]
# 或者: from AnyQt.QtWidgets.QLabel import setSizePolicy [as 别名]
def __init__(self):
super().__init__()
self.data = None
self.distributions = None
self.contingencies = None
self.var = self.cvar = None
varbox = gui.vBox(self.controlArea, "Variable")
self.varmodel = itemmodels.VariableListModel()
self.groupvarmodel = []
self.varview = QListView(
selectionMode=QListView.SingleSelection)
self.varview.setSizePolicy(
QSizePolicy.Minimum, QSizePolicy.Expanding)
self.varview.setModel(self.varmodel)
self.varview.setSelectionModel(
itemmodels.ListSingleSelectionModel(self.varmodel))
self.varview.selectionModel().selectionChanged.connect(
self._on_variable_idx_changed)
varbox.layout().addWidget(self.varview)
box = gui.vBox(self.controlArea, "Precision")
gui.separator(self.controlArea, 4, 4)
box2 = gui.hBox(box)
self.l_smoothing_l = gui.widgetLabel(box2, "Smooth")
gui.hSlider(box2, self, "smoothing_index",
minValue=0, maxValue=len(self.smoothing_facs) - 1,
callback=self._on_set_smoothing, createLabel=False)
self.l_smoothing_r = gui.widgetLabel(box2, "Precise")
self.cb_disc_cont = gui.checkBox(
gui.indentedBox(box, sep=4),
self, "disc_cont", "Bin numeric variables",
callback=self._on_groupvar_idx_changed,
tooltip="Show numeric variables as categorical.")
box = gui.vBox(self.controlArea, "Group by")
self.icons = gui.attributeIconDict
self.groupvarview = gui.comboBox(
box, self, "groupvar_idx",
callback=self._on_groupvar_idx_changed,
valueType=str, contentsLength=12)
box2 = gui.indentedBox(box, sep=4)
self.cb_rel_freq = gui.checkBox(
box2, self, "relative_freq", "Show relative frequencies",
callback=self._on_relative_freq_changed,
tooltip="Normalize probabilities so that probabilities "
"for each group-by value sum to 1.")
gui.separator(box2)
self.cb_prob = gui.comboBox(
box2, self, "show_prob", label="Show probabilities:",
orientation=Qt.Horizontal,
callback=self._on_relative_freq_changed,
tooltip="Show probabilities for a chosen group-by value "
"(at each point probabilities for all group-by values sum to 1).")
self.plotview = pg.PlotWidget(background=None)
self.plotview.setRenderHint(QPainter.Antialiasing)
self.mainArea.layout().addWidget(self.plotview)
w = QLabel()
w.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.mainArea.layout().addWidget(w, Qt.AlignCenter)
self.ploti = pg.PlotItem()
self.plot = self.ploti.vb
self.ploti.hideButtons()
self.plotview.setCentralItem(self.ploti)
self.plot_prob = pg.ViewBox()
self.ploti.hideAxis('right')
self.ploti.scene().addItem(self.plot_prob)
self.ploti.getAxis("right").linkToView(self.plot_prob)
self.ploti.getAxis("right").setLabel("Probability")
self.plot_prob.setZValue(10)
self.plot_prob.setXLink(self.ploti)
self.update_views()
self.ploti.vb.sigResized.connect(self.update_views)
self.plot_prob.setRange(yRange=[0, 1])
def disable_mouse(plot):
plot.setMouseEnabled(False, False)
plot.setMenuEnabled(False)
disable_mouse(self.plot)
disable_mouse(self.plot_prob)
self.tooltip_items = []
self.plot.scene().installEventFilter(
HelpEventDelegate(self.help_event, self))
pen = QPen(self.palette().color(QPalette.Text))
for axis in ("left", "bottom"):
self.ploti.getAxis(axis).setPen(pen)
self._legend = LegendItem()
self._legend.setParentItem(self.plot)
self._legend.hide()
#.........这里部分代码省略.........
示例5: OWDatabasesUpdate
# 需要导入模块: from AnyQt.QtWidgets import QLabel [as 别名]
# 或者: from AnyQt.QtWidgets.QLabel import setSizePolicy [as 别名]
class OWDatabasesUpdate(OWWidget):
name = "Databases Update"
description = "Update local systems biology databases."
icon = "../widgets/icons/Databases.svg"
priority = 10
inputs = []
outputs = []
want_main_area = False
def __init__(self, parent=None, signalManager=None,
name="Databases update"):
OWWidget.__init__(self, parent, signalManager, name,
wantMainArea=False)
self.searchString = ""
fbox = gui.widgetBox(self.controlArea, "Filter")
self.completer = TokenListCompleter(
self, caseSensitivity=Qt.CaseInsensitive)
self.lineEditFilter = QLineEdit(textChanged=self.SearchUpdate)
self.lineEditFilter.setCompleter(self.completer)
fbox.layout().addWidget(self.lineEditFilter)
box = gui.widgetBox(self.controlArea, "Files")
self.filesView = QTreeWidget(self)
self.filesView.setHeaderLabels(
["", "Data Source", "Update", "Last Updated", "Size"])
self.filesView.setRootIsDecorated(False)
self.filesView.setUniformRowHeights(True)
self.filesView.setSelectionMode(QAbstractItemView.NoSelection)
self.filesView.setSortingEnabled(True)
self.filesView.sortItems(1, Qt.AscendingOrder)
self.filesView.setItemDelegateForColumn(
0, UpdateOptionsItemDelegate(self.filesView))
self.filesView.model().layoutChanged.connect(self.SearchUpdate)
box.layout().addWidget(self.filesView)
box = gui.widgetBox(self.controlArea, orientation="horizontal")
self.updateButton = gui.button(
box, self, "Update all",
callback=self.UpdateAll,
tooltip="Update all updatable files",
)
self.downloadButton = gui.button(
box, self, "Download all",
callback=self.DownloadFiltered,
tooltip="Download all filtered files shown"
)
self.cancelButton = gui.button(
box, self, "Cancel", callback=self.Cancel,
tooltip="Cancel scheduled downloads/updates."
)
self.retryButton = gui.button(
box, self, "Reconnect", callback=self.RetrieveFilesList
)
self.retryButton.hide()
gui.rubber(box)
self.warning(0)
box = gui.widgetBox(self.controlArea, orientation="horizontal")
gui.rubber(box)
self.infoLabel = QLabel()
self.infoLabel.setAlignment(Qt.AlignCenter)
self.controlArea.layout().addWidget(self.infoLabel)
self.infoLabel.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.updateItems = []
self.resize(800, 600)
self.progress = ProgressState(self, maximum=3)
self.progress.valueChanged.connect(self._updateProgress)
self.progress.rangeChanged.connect(self._updateProgress)
self.executor = ThreadExecutor(
threadPool=QThreadPool(maxThreadCount=2)
)
task = Task(self, function=self.RetrieveFilesList)
task.exceptionReady.connect(self.HandleError)
task.start()
self._tasks = []
self._haveProgress = False
def RetrieveFilesList(self):
self.retryButton.hide()
#.........这里部分代码省略.........
示例6: MessageWidget
# 需要导入模块: from AnyQt.QtWidgets import QLabel [as 别名]
# 或者: from AnyQt.QtWidgets.QLabel import setSizePolicy [as 别名]
class MessageWidget(QWidget):
"""
A widget displaying a simple message to the user.
This is an alternative to a full QMessageBox intended for inline
modeless messages.
[[icon] {Message text} (Ok) (Cancel)]
"""
#: Emitted when a button with the AcceptRole is clicked
accepted = Signal()
#: Emitted when a button with the RejectRole is clicked
rejected = Signal()
#: Emitted when a button with the HelpRole is clicked
helpRequested = Signal()
#: Emitted when a button is clicked
clicked = Signal(QAbstractButton)
class StandardButton(enum.IntEnum):
NoButton, Ok, Close, Help = 0x0, 0x1, 0x2, 0x4
NoButton, Ok, Close, Help = list(StandardButton)
class ButtonRole(enum.IntEnum):
InvalidRole, AcceptRole, RejectRole, HelpRole = 0, 1, 2, 3
InvalidRole, AcceptRole, RejectRole, HelpRole = list(ButtonRole)
_Button = namedtuple("_Button", ["button", "role", "stdbutton"])
def __init__(self, parent=None, icon=QIcon(), text="", wordWrap=False,
textFormat=Qt.AutoText, standardButtons=NoButton, **kwargs):
super().__init__(parent, **kwargs)
self.__text = text
self.__icon = QIcon()
self.__wordWrap = wordWrap
self.__standardButtons = MessageWidget.NoButton
self.__buttons = []
layout = QHBoxLayout()
layout.setContentsMargins(8, 0, 8, 0)
self.__iconlabel = QLabel(objectName="icon-label")
self.__iconlabel.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
self.__textlabel = QLabel(objectName="text-label", text=text,
wordWrap=wordWrap, textFormat=textFormat)
if sys.platform == "darwin":
self.__textlabel.setAttribute(Qt.WA_MacSmallSize)
layout.addWidget(self.__iconlabel)
layout.addWidget(self.__textlabel)
self.setLayout(layout)
self.setIcon(icon)
self.setStandardButtons(standardButtons)
def setText(self, text):
"""
Set the current message text.
:type message: str
"""
if self.__text != text:
self.__text = text
self.__textlabel.setText(text)
def text(self):
"""
Return the current message text.
:rtype: str
"""
return self.__text
def setIcon(self, icon):
"""
Set the message icon.
:type icon: QIcon | QPixmap | QString | QStyle.StandardPixmap
"""
if isinstance(icon, QStyle.StandardPixmap):
icon = self.style().standardIcon(icon)
else:
icon = QIcon(icon)
if self.__icon != icon:
self.__icon = QIcon(icon)
if not self.__icon.isNull():
size = self.style().pixelMetric(
QStyle.PM_SmallIconSize, None, self)
pm = self.__icon.pixmap(QSize(size, size))
else:
pm = QPixmap()
self.__iconlabel.setPixmap(pm)
self.__iconlabel.setVisible(not pm.isNull())
def icon(self):
"""
Return the current icon.
#.........这里部分代码省略.........
示例7: OWMultifile
# 需要导入模块: from AnyQt.QtWidgets import QLabel [as 别名]
# 或者: from AnyQt.QtWidgets.QLabel import setSizePolicy [as 别名]
class OWMultifile(Orange.widgets.data.owfile.OWFile, RecentPathsWidgetMixin):
name = "Multifile"
id = "orangecontrib.spectroscopy.widgets.files"
icon = "icons/multifile.svg"
description = "Read data from input files " \
"and send a data table to the output."
priority = 10000
replaces = ["orangecontrib.infrared.widgets.owfiles.OWFiles",
"orangecontrib.infrared.widgets.owmultifile.OWMultifile"]
file_idx = []
sheet = Orange.widgets.settings.Setting(None)
label = Orange.widgets.settings.Setting("")
recent_paths = Orange.widgets.settings.Setting([])
def __init__(self):
widget.OWWidget.__init__(self)
RecentPathsWidgetMixin.__init__(self)
self.domain = None
self.data = None
self.loaded_file = ""
self.sheets = []
self.lb = gui.listBox(self.controlArea, self, "file_idx",
selectionMode=QListWidget.MultiSelection)
layout = QGridLayout()
gui.widgetBox(self.controlArea, margin=0, orientation=layout)
file_button = gui.button(
None, self, ' ...', callback=self.browse_files, autoDefault=False)
file_button.setIcon(self.style().standardIcon(
QStyle.SP_DirOpenIcon))
file_button.setSizePolicy(Policy.Maximum, Policy.Fixed)
layout.addWidget(file_button, 0, 0)
remove_button = gui.button(
None, self, 'Remove', callback=self.remove_item)
clear_button = gui.button(
None, self, 'Clear', callback=self.clear)
layout.addWidget(remove_button, 0, 1)
layout.addWidget(clear_button, 0, 2)
reload_button = gui.button(
None, self, "Reload", callback=self.load_data, autoDefault=False)
reload_button.setIcon(self.style().standardIcon(QStyle.SP_BrowserReload))
reload_button.setSizePolicy(Policy.Fixed, Policy.Fixed)
layout.addWidget(reload_button, 0, 7)
self.sheet_box = gui.hBox(None, addToLayout=False, margin=0)
self.sheet_combo = gui.comboBox(None, self, "xls_sheet",
callback=self.select_sheet,
sendSelectedValue=True)
self.sheet_combo.setSizePolicy(
Policy.MinimumExpanding, Policy.Fixed)
self.sheet_label = QLabel()
self.sheet_label.setText('Sheet')
self.sheet_label.setSizePolicy(
Policy.MinimumExpanding, Policy.Fixed)
self.sheet_box.layout().addWidget(
self.sheet_label, Qt.AlignLeft)
self.sheet_box.layout().addWidget(
self.sheet_combo, Qt.AlignVCenter)
layout.addWidget(self.sheet_box, 2, 1)
self.sheet_box.hide()
layout.addWidget(self.sheet_box, 0, 5)
label_box = gui.hBox(None, addToLayout=False, margin=0)
label = gui.lineEdit(label_box, self, "label", callback=self.set_label,
label="Label", orientation=Qt.Horizontal)
layout.addWidget(label_box, 0, 6)
layout.setColumnStretch(3, 2)
box = gui.widgetBox(self.controlArea, "Columns (Double click to edit)")
self.domain_editor = DomainEditor(self)
self.editor_model = self.domain_editor.model()
box.layout().addWidget(self.domain_editor)
for i, rp in enumerate(self.recent_paths):
self.lb.addItem(rp.abspath)
# TODO unresolved paths just disappear! Modify _relocate_recent_files
box = gui.hBox(self.controlArea)
gui.rubber(box)
box.layout().addWidget(self.report_button)
self.report_button.setFixedWidth(170)
self.apply_button = gui.button(
box, self, "Apply", callback=self.apply_domain_edit)
self.apply_button.setEnabled(False)
self.apply_button.setFixedWidth(170)
self.editor_model.dataChanged.connect(
lambda: self.apply_button.setEnabled(True))
#.........这里部分代码省略.........