本文整理汇总了Python中AnyQt.QtWidgets.QHBoxLayout.addStretch方法的典型用法代码示例。如果您正苦于以下问题:Python QHBoxLayout.addStretch方法的具体用法?Python QHBoxLayout.addStretch怎么用?Python QHBoxLayout.addStretch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QHBoxLayout
的用法示例。
在下文中一共展示了QHBoxLayout.addStretch方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dock_standalone
# 需要导入模块: from AnyQt.QtWidgets import QHBoxLayout [as 别名]
# 或者: from AnyQt.QtWidgets.QHBoxLayout import addStretch [as 别名]
def test_dock_standalone(self):
widget = QWidget()
layout = QHBoxLayout()
widget.setLayout(layout)
layout.addStretch(1)
widget.show()
dock = CollapsibleDockWidget()
layout.addWidget(dock)
list_view = QListView()
list_view.setModel(QStringListModel(["a", "b"], list_view))
label = QLabel("A label. ")
label.setWordWrap(True)
dock.setExpandedWidget(label)
dock.setCollapsedWidget(list_view)
dock.setExpanded(True)
self.app.processEvents()
def toogle():
dock.setExpanded(not dock.expanded())
self.singleShot(2000, toogle)
toogle()
self.app.exec_()
示例2: _setup_gui_labels
# 需要导入模块: from AnyQt.QtWidgets import QHBoxLayout [as 别名]
# 或者: from AnyQt.QtWidgets.QHBoxLayout import addStretch [as 别名]
def _setup_gui_labels(self):
vlayout = QVBoxLayout()
vlayout.setContentsMargins(0, 0, 0, 0)
vlayout.setSpacing(1)
self.labels_edit = QTreeView()
self.labels_edit.setEditTriggers(QTreeView.CurrentChanged)
self.labels_edit.setRootIsDecorated(False)
self.labels_model = DictItemsModel()
self.labels_edit.setModel(self.labels_model)
self.labels_edit.selectionModel().selectionChanged.connect(
self.on_label_selection_changed)
# Necessary signals to know when the labels change
self.labels_model.dataChanged.connect(self.on_labels_changed)
self.labels_model.rowsInserted.connect(self.on_labels_changed)
self.labels_model.rowsRemoved.connect(self.on_labels_changed)
vlayout.addWidget(self.labels_edit)
hlayout = QHBoxLayout()
hlayout.setContentsMargins(0, 0, 0, 0)
hlayout.setSpacing(1)
self.add_label_action = QAction(
"+", self,
toolTip="Add a new label.",
triggered=self.on_add_label,
enabled=False,
shortcut=QKeySequence(QKeySequence.New))
self.remove_label_action = QAction(
unicodedata.lookup("MINUS SIGN"), self,
toolTip="Remove selected label.",
triggered=self.on_remove_label,
enabled=False,
shortcut=QKeySequence(QKeySequence.Delete))
button_size = gui.toolButtonSizeHint()
button_size = QSize(button_size, button_size)
button = QToolButton(self)
button.setFixedSize(button_size)
button.setDefaultAction(self.add_label_action)
hlayout.addWidget(button)
button = QToolButton(self)
button.setFixedSize(button_size)
button.setDefaultAction(self.remove_label_action)
hlayout.addWidget(button)
hlayout.addStretch(10)
vlayout.addLayout(hlayout)
self.main_form.addRow("Labels:", vlayout)
示例3: test_dock_standalone
# 需要导入模块: from AnyQt.QtWidgets import QHBoxLayout [as 别名]
# 或者: from AnyQt.QtWidgets.QHBoxLayout import addStretch [as 别名]
def test_dock_standalone(self):
widget = QWidget()
layout = QHBoxLayout()
widget.setLayout(layout)
layout.addStretch(1)
widget.show()
dock = CollapsibleDockWidget()
layout.addWidget(dock)
list_view = QListView()
list_view.setModel(QStringListModel(["a", "b"], list_view))
label = QLabel("A label. ")
label.setWordWrap(True)
dock.setExpandedWidget(label)
dock.setCollapsedWidget(list_view)
dock.setExpanded(True)
dock.setExpanded(False)
timer = QTimer(dock, interval=200)
timer.timeout.connect(lambda: dock.setExpanded(not dock.expanded()))
timer.start()
示例4: __init__
# 需要导入模块: from AnyQt.QtWidgets import QHBoxLayout [as 别名]
# 或者: from AnyQt.QtWidgets.QHBoxLayout import addStretch [as 别名]
def __init__(self, *args):
QWidget.__init__(self, *args)
self.setContentsMargins(0, 0, 0, 0)
gridLayout = QGridLayout()
gridLayout.setContentsMargins(0, 0, 0, 0)
gridLayout.setSpacing(1)
model = QStandardItemModel(self)
model.rowsInserted.connect(self.__changed)
model.rowsRemoved.connect(self.__changed)
model.dataChanged.connect(self.__changed)
self._listView = QListView(self)
self._listView.setModel(model)
# self._listView.setDragEnabled(True)
self._listView.setDropIndicatorShown(True)
self._listView.setDragDropMode(QListView.InternalMove)
self._listView.viewport().setAcceptDrops(True)
self._listView.setMinimumHeight(100)
gridLayout.addWidget(self._listView, 0, 0, 2, 2)
vButtonLayout = QVBoxLayout()
self._upAction = QAction(
"\u2191", self, toolTip="Move up")
self._upButton = QToolButton(self)
self._upButton.setDefaultAction(self._upAction)
self._upButton.setSizePolicy(
QSizePolicy.Fixed, QSizePolicy.MinimumExpanding)
self._downAction = QAction(
"\u2193", self, toolTip="Move down")
self._downButton = QToolButton(self)
self._downButton.setDefaultAction(self._downAction)
self._downButton.setSizePolicy(
QSizePolicy.Fixed, QSizePolicy.MinimumExpanding)
vButtonLayout.addWidget(self._upButton)
vButtonLayout.addWidget(self._downButton)
gridLayout.addLayout(vButtonLayout, 0, 2, 2, 1)
hButtonLayout = QHBoxLayout()
self._addAction = QAction("+", self)
self._addButton = QToolButton(self)
self._addButton.setDefaultAction(self._addAction)
self._removeAction = QAction("-", self)
self._removeButton = QToolButton(self)
self._removeButton.setDefaultAction(self._removeAction)
hButtonLayout.addWidget(self._addButton)
hButtonLayout.addWidget(self._removeButton)
hButtonLayout.addStretch(10)
gridLayout.addLayout(hButtonLayout, 2, 0, 1, 2)
self.setLayout(gridLayout)
self._addAction.triggered.connect(self._onAddAction)
self._removeAction.triggered.connect(self._onRemoveAction)
self._upAction.triggered.connect(self._onUpAction)
self._downAction.triggered.connect(self._onDownAction)
示例5: __init__
# 需要导入模块: from AnyQt.QtWidgets import QHBoxLayout [as 别名]
# 或者: from AnyQt.QtWidgets.QHBoxLayout import addStretch [as 别名]
def __init__(self, data):
icon = QApplication.style().standardIcon(QStyle.SP_MessageBoxWarning)
F = self.DataField
def _finished(*, key=(data.get(F.MODULE),
data.get(F.WIDGET_MODULE)),
filename=data.get(F.WIDGET_SCHEME)):
self._cache.add(key)
try:
os.remove(filename)
except Exception:
pass
super().__init__(None, Qt.Window, modal=True,
sizeGripEnabled=True, windowIcon=icon,
windowTitle='Unexpected Error',
finished=_finished)
self._data = data
layout = QVBoxLayout(self)
self.setLayout(layout)
labels = QWidget(self)
labels_layout = QHBoxLayout(self)
labels.setLayout(labels_layout)
labels_layout.addWidget(QLabel(pixmap=icon.pixmap(50, 50)))
labels_layout.addWidget(QLabel(
'The program encountered an unexpected error. Please<br>'
'report it anonymously to the developers.<br><br>'
'The following data will be reported:'))
labels_layout.addStretch(1)
layout.addWidget(labels)
font = QFont('Monospace', 10)
font.setStyleHint(QFont.Monospace)
font.setFixedPitch(True)
textbrowser = QTextBrowser(self,
font=font,
openLinks=False,
lineWrapMode=QTextBrowser.NoWrap,
anchorClicked=QDesktopServices.openUrl)
layout.addWidget(textbrowser)
def _reload_text():
add_scheme = cb.isChecked()
settings.setValue('error-reporting/add-scheme', add_scheme)
lines = ['<table>']
for k, v in data.items():
if k.startswith('_'):
continue
_v, v = v, escape(str(v))
if k == F.WIDGET_SCHEME:
if not add_scheme:
continue
v = '<a href="{}">{}</a>'.format(urljoin('file:', pathname2url(_v)), v)
if k in (F.STACK_TRACE, F.LOCALS):
v = v.replace('\n', '<br>').replace(' ', ' ')
lines.append('<tr><th align="left">{}:</th><td>{}</td></tr>'.format(k, v))
lines.append('</table>')
textbrowser.setHtml(''.join(lines))
settings = QSettings()
cb = QCheckBox(
'Include workflow (data will NOT be transmitted)', self,
checked=settings.value('error-reporting/add-scheme', True, type=bool))
cb.stateChanged.connect(_reload_text)
_reload_text()
layout.addWidget(cb)
buttons = QWidget(self)
buttons_layout = QHBoxLayout(self)
buttons.setLayout(buttons_layout)
buttons_layout.addWidget(
QPushButton('Send Report (Thanks!)', default=True, clicked=self.accept))
buttons_layout.addWidget(QPushButton("Don't Send", default=False, clicked=self.reject))
layout.addWidget(buttons)
示例6: PreprocessorModule
# 需要导入模块: from AnyQt.QtWidgets import QHBoxLayout [as 别名]
# 或者: from AnyQt.QtWidgets.QHBoxLayout import addStretch [as 别名]
class PreprocessorModule(gui.OWComponent, QWidget):
"""The base widget for the pre-processing modules."""
change_signal = pyqtSignal() # Emitted when the settings are changed.
title = NotImplemented
attribute = NotImplemented
methods = NotImplemented
single_method = True
toggle_enabled = True
enabled = settings.Setting(True)
disabled_value = None
Layout = QGridLayout
def __init__(self, master):
QWidget.__init__(self)
gui.OWComponent.__init__(self, master)
self.master = master
# Title bar.
title_holder = QWidget()
title_holder.setSizePolicy(QSizePolicy.MinimumExpanding,
QSizePolicy.Fixed)
title_holder.setStyleSheet("""
.QWidget {
background: qlineargradient( x1:0 y1:0, x2:0 y2:1,
stop:0 #F8F8F8, stop:1 #C8C8C8);
border-bottom: 1px solid #B3B3B3;
}
""")
self.titleArea = QHBoxLayout()
self.titleArea.setContentsMargins(10, 5, 10, 5)
self.titleArea.setSpacing(0)
title_holder.setLayout(self.titleArea)
self.title_label = QLabel(self.title)
self.title_label.mouseDoubleClickEvent = self.on_toggle
self.title_label.setStyleSheet('font-size: 12px; border: 2px solid red;')
self.titleArea.addWidget(self.title_label)
self.off_label = QLabel('[disabled]')
self.off_label.setStyleSheet('color: #B0B0B0; margin-left: 5px;')
self.titleArea.addWidget(self.off_label)
self.off_label.hide()
self.titleArea.addStretch()
# Root.
self.rootArea = QVBoxLayout()
self.rootArea.setContentsMargins(0, 0, 0, 0)
self.rootArea.setSpacing(0)
self.setLayout(self.rootArea)
self.rootArea.addWidget(title_holder)
self.contents = QWidget()
contentArea = QVBoxLayout()
contentArea.setContentsMargins(15, 10, 15, 10)
self.contents.setLayout(contentArea)
self.rootArea.addWidget(self.contents)
self.method_layout = self.Layout()
self.setup_method_layout()
self.contents.layout().addLayout(self.method_layout)
if self.toggle_enabled:
self.on_off_button = OnOffButton(enabled=self.enabled)
self.on_off_button.stateChanged.connect(self.on_toggle)
self.on_off_button.setContentsMargins(0, 0, 0, 0)
self.titleArea.addWidget(self.on_off_button)
self.display_widget()
@staticmethod
def get_tooltip(method):
return ' '.join([l.strip() for l in method.__doc__.split('\n')]).strip('.') \
if method.__doc__ else None
@staticmethod
def textify(text):
return text.replace('&', '&&')
@property
def value(self):
if self.enabled:
return self.get_value()
return self.disabled_value
def setup_method_layout(self):
raise NotImplementedError
def on_toggle(self, event=None):
# Activated when the widget is enabled/disabled.
self.enabled = not self.enabled
self.display_widget()
self.update_value()
def display_widget(self):
if self.enabled:
self.off_label.hide()
self.contents.show()
self.title_label.setStyleSheet('color: #000000;')
else:
#.........这里部分代码省略.........
示例7: __init__
# 需要导入模块: from AnyQt.QtWidgets import QHBoxLayout [as 别名]
# 或者: from AnyQt.QtWidgets.QHBoxLayout import addStretch [as 别名]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
form = self.layout().itemAt(0)
assert isinstance(form, QFormLayout)
#: A list model of discrete variable's values.
self.values_model = itemmodels.PyListModel(
flags=Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable
)
vlayout = QVBoxLayout(spacing=1, margin=0)
self.values_edit = QListView(
editTriggers=QListView.DoubleClicked | QListView.EditKeyPressed
)
self.values_edit.setItemDelegate(CategoriesEditDelegate(self))
self.values_edit.setModel(self.values_model)
self.values_model.dataChanged.connect(self.on_values_changed)
self.values_edit.selectionModel().selectionChanged.connect(
self.on_value_selection_changed)
self.values_model.layoutChanged.connect(self.on_value_selection_changed)
self.values_model.rowsMoved.connect(self.on_value_selection_changed)
vlayout.addWidget(self.values_edit)
hlayout = QHBoxLayout(spacing=1, margin=0)
self.categories_action_group = group = QActionGroup(
self, objectName="action-group-categories", enabled=False
)
self.move_value_up = QAction(
"\N{UPWARDS ARROW}", group,
toolTip="Move the selected item up.",
shortcut=QKeySequence(Qt.ControlModifier | Qt.AltModifier |
Qt.Key_BracketLeft),
shortcutContext=Qt.WidgetShortcut,
)
self.move_value_up.triggered.connect(self.move_up)
self.move_value_down = QAction(
"\N{DOWNWARDS ARROW}", group,
toolTip="Move the selected item down.",
shortcut=QKeySequence(Qt.ControlModifier | Qt.AltModifier |
Qt.Key_BracketRight),
shortcutContext=Qt.WidgetShortcut,
)
self.move_value_down.triggered.connect(self.move_down)
self.add_new_item = QAction(
"+", group,
objectName="action-add-item",
toolTip="Append a new item.",
shortcut=QKeySequence(QKeySequence.New),
shortcutContext=Qt.WidgetShortcut,
)
self.remove_item = QAction(
"\N{MINUS SIGN}", group,
objectName="action-remove-item",
toolTip="Delete the selected item.",
shortcut=QKeySequence(QKeySequence.Delete),
shortcutContext=Qt.WidgetShortcut,
)
self.add_new_item.triggered.connect(self._add_category)
self.remove_item.triggered.connect(self._remove_category)
button1 = FixedSizeButton(
self, defaultAction=self.move_value_up,
accessibleName="Move up"
)
button2 = FixedSizeButton(
self, defaultAction=self.move_value_down,
accessibleName="Move down"
)
button3 = FixedSizeButton(
self, defaultAction=self.add_new_item,
accessibleName="Add"
)
button4 = FixedSizeButton(
self, defaultAction=self.remove_item,
accessibleName="Remove"
)
self.values_edit.addActions([self.move_value_up, self.move_value_down,
self.add_new_item, self.remove_item])
hlayout.addWidget(button1)
hlayout.addWidget(button2)
hlayout.addSpacing(3)
hlayout.addWidget(button3)
hlayout.addWidget(button4)
hlayout.addStretch(10)
vlayout.addLayout(hlayout)
form.insertRow(1, "Values:", vlayout)
QWidget.setTabOrder(self.name_edit, self.values_edit)
QWidget.setTabOrder(self.values_edit, button1)
QWidget.setTabOrder(button1, button2)
QWidget.setTabOrder(button2, button3)
QWidget.setTabOrder(button3, button4)