本文整理汇总了Python中qtpy.QtWidgets.QGridLayout.setContentsMargins方法的典型用法代码示例。如果您正苦于以下问题:Python QGridLayout.setContentsMargins方法的具体用法?Python QGridLayout.setContentsMargins怎么用?Python QGridLayout.setContentsMargins使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QGridLayout
的用法示例。
在下文中一共展示了QGridLayout.setContentsMargins方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_file_combobox
# 需要导入模块: from qtpy.QtWidgets import QGridLayout [as 别名]
# 或者: from qtpy.QtWidgets.QGridLayout import setContentsMargins [as 别名]
def create_file_combobox(self, text, choices, option, default=NoDefault,
tip=None, restart=False, filters=None,
adjust_to_contents=False,
default_line_edit=False):
"""choices: couples (name, key)"""
combobox = FileComboBox(self, adjust_to_contents=adjust_to_contents,
default_line_edit=default_line_edit)
combobox.restart_required = restart
combobox.label_text = text
edit = combobox.lineEdit()
edit.label_text = text
edit.restart_required = restart
self.lineedits[edit] = (option, default)
if tip is not None:
combobox.setToolTip(tip)
combobox.addItems(choices)
msg = _('Invalid file path')
self.validate_data[edit] = (osp.isfile, msg)
browse_btn = QPushButton(ima.icon('FileIcon'), '', self)
browse_btn.setToolTip(_("Select file"))
browse_btn.clicked.connect(lambda: self.select_file(edit, filters))
layout = QGridLayout()
layout.addWidget(combobox, 0, 0, 0, 9)
layout.addWidget(browse_btn, 0, 10)
layout.setContentsMargins(0, 0, 0, 0)
widget = QWidget(self)
widget.combobox = combobox
widget.browse_btn = browse_btn
widget.setLayout(layout)
return widget
示例2: setup_gui
# 需要导入模块: from qtpy.QtWidgets import QGridLayout [as 别名]
# 或者: from qtpy.QtWidgets.QGridLayout import setContentsMargins [as 别名]
def setup_gui(self):
"""Setup the main layout of the widget."""
layout = QGridLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(self.canvas, 0, 1)
layout.addLayout(self.setup_toolbar(), 0, 3, 2, 1)
layout.setColumnStretch(0, 100)
layout.setColumnStretch(2, 100)
layout.setRowStretch(1, 100)
示例3: QuadHistogram
# 需要导入模块: from qtpy.QtWidgets import QGridLayout [as 别名]
# 或者: from qtpy.QtWidgets.QGridLayout import setContentsMargins [as 别名]
class QuadHistogram(QFrame):
'''A class which uses ColorHistogram to draw
the 4 histograms of an image. R, G, B, and Value.
The 4 histograms are layout out in a grid,
and can be specified horizontal or vertical,
and in which order ie. ['R', 'G', 'B', 'V']
'''
def __init__(self, img, layout='vertical', order=['R', 'G', 'B', 'V']):
QFrame.__init__(self)
r, g, b, v = histograms(img, 100)
self.r_hist = ColorHistogram(r, (255, 0, 0))
self.g_hist = ColorHistogram(g, (0, 255, 0))
self.b_hist = ColorHistogram(b, (0, 0, 255))
self.v_hist = ColorHistogram(v, (0, 0, 0))
self.setFrameStyle(QFrame.StyledPanel | QFrame.Sunken)
self.layout = QGridLayout(self)
self.layout.setContentsMargins(0, 0, 0, 0)
order_map = {'R': self.r_hist, 'G': self.g_hist, 'B': self.b_hist,
'V': self.v_hist}
if layout == 'vertical':
for i in range(len(order)):
self.layout.addWidget(order_map[order[i]], i, 0)
elif layout == 'horizontal':
for i in range(len(order)):
self.layout.addWidget(order_map[order[i]], 0, i)
def update_hists(self, img):
r, g, b, v = histograms(img, 100)
self.r_hist.update_hist(r, (255, 0, 0))
self.g_hist.update_hist(g, (0, 255, 0))
self.b_hist.update_hist(b, (0, 0, 255))
self.v_hist.update_hist(v, (0, 0, 0))
示例4: PyDMScaleIndicator
# 需要导入模块: from qtpy.QtWidgets import QGridLayout [as 别名]
# 或者: from qtpy.QtWidgets.QGridLayout import setContentsMargins [as 别名]
#.........这里部分代码省略.........
self.upper_label.setAlignment(Qt.AlignLeft | Qt.AlignTop)
elif inverted:
self.lower_label.setAlignment(Qt.AlignLeft | Qt.AlignTop)
self.upper_label.setAlignment(Qt.AlignLeft | Qt.AlignBottom)
else:
if value_position == Qt.LeftEdge:
self.widget_layout.addItem(self.limits_layout, 0, 1)
self.widget_layout.addWidget(self.scale_indicator, 0, 2)
elif value_position == Qt.RightEdge:
self.widget_layout.addItem(self.limits_layout, 0, 0)
self.widget_layout.addWidget(self.scale_indicator, 0, 1)
self.widget_layout.addWidget(self.value_label, 0, 2)
elif value_position == Qt.TopEdge:
self.widget_layout.addWidget(self.value_label, 0, 0, 1, 2)
self.widget_layout.addItem(self.limits_layout, 1, 0)
self.widget_layout.addWidget(self.scale_indicator, 1, 1)
elif value_position == Qt.BottomEdge:
self.widget_layout.addItem(self.limits_layout, 0, 0)
self.widget_layout.addWidget(self.scale_indicator, 0, 1)
self.widget_layout.addWidget(self.value_label, 1, 0, 1, 2)
if not inverted:
self.lower_label.setAlignment(Qt.AlignRight | Qt.AlignBottom)
self.upper_label.setAlignment(Qt.AlignRight | Qt.AlignTop)
elif inverted:
self.lower_label.setAlignment(Qt.AlignRight | Qt.AlignTop)
self.upper_label.setAlignment(Qt.AlignRight | Qt.AlignBottom)
self.value_label.setAlignment(Qt.AlignCenter)
if self.layout() is not None:
# Trick to remove the existing layout by re-parenting it in an empty widget.
QWidget().setLayout(self.layout())
self.widget_layout.setContentsMargins(1, 1, 1, 1)
self.setLayout(self.widget_layout)
@Property(bool)
def showValue(self):
"""
Whether or not the current value should be displayed on the scale.
Returns
-------
bool
"""
return self._show_value
@showValue.setter
def showValue(self, checked):
"""
Whether or not the current value should be displayed on the scale.
Parameters
----------
checked : bool
"""
if self._show_value != bool(checked):
self._show_value = checked
if checked:
self.value_label.show()
else:
self.value_label.hide()
@Property(bool)
def showLimits(self):
"""
示例5: __init__
# 需要导入模块: from qtpy.QtWidgets import QGridLayout [as 别名]
# 或者: from qtpy.QtWidgets.QGridLayout import setContentsMargins [as 别名]
def __init__(self, parent, enable_replace=False):
QWidget.__init__(self, parent)
self.enable_replace = enable_replace
self.editor = None
self.is_code_editor = None
glayout = QGridLayout()
glayout.setContentsMargins(0, 0, 0, 0)
self.setLayout(glayout)
self.close_button = create_toolbutton(self, triggered=self.hide,
icon=ima.icon('DialogCloseButton'))
glayout.addWidget(self.close_button, 0, 0)
# Find layout
self.search_text = PatternComboBox(self, tip=_("Search string"),
adjust_to_minimum=False)
self.search_text.valid.connect(
lambda state:
self.find(changed=False, forward=True, rehighlight=False))
self.search_text.lineEdit().textEdited.connect(
self.text_has_been_edited)
self.previous_button = create_toolbutton(self,
triggered=self.find_previous,
icon=ima.icon('ArrowUp'))
self.next_button = create_toolbutton(self,
triggered=self.find_next,
icon=ima.icon('ArrowDown'))
self.next_button.clicked.connect(self.update_search_combo)
self.previous_button.clicked.connect(self.update_search_combo)
self.re_button = create_toolbutton(self, icon=ima.icon('advanced'),
tip=_("Regular expression"))
self.re_button.setCheckable(True)
self.re_button.toggled.connect(lambda state: self.find())
self.case_button = create_toolbutton(self,
icon=get_icon("upper_lower.png"),
tip=_("Case Sensitive"))
self.case_button.setCheckable(True)
self.case_button.toggled.connect(lambda state: self.find())
self.words_button = create_toolbutton(self,
icon=get_icon("whole_words.png"),
tip=_("Whole words"))
self.words_button.setCheckable(True)
self.words_button.toggled.connect(lambda state: self.find())
self.highlight_button = create_toolbutton(self,
icon=get_icon("highlight.png"),
tip=_("Highlight matches"))
self.highlight_button.setCheckable(True)
self.highlight_button.toggled.connect(self.toggle_highlighting)
hlayout = QHBoxLayout()
self.widgets = [self.close_button, self.search_text,
self.previous_button, self.next_button,
self.re_button, self.case_button, self.words_button,
self.highlight_button]
for widget in self.widgets[1:]:
hlayout.addWidget(widget)
glayout.addLayout(hlayout, 0, 1)
# Replace layout
replace_with = QLabel(_("Replace with:"))
self.replace_text = PatternComboBox(self, adjust_to_minimum=False,
tip=_('Replace string'))
self.replace_button = create_toolbutton(self,
text=_('Replace/find'),
icon=ima.icon('DialogApplyButton'),
triggered=self.replace_find,
text_beside_icon=True)
self.replace_button.clicked.connect(self.update_replace_combo)
self.replace_button.clicked.connect(self.update_search_combo)
self.all_check = QCheckBox(_("Replace all"))
self.replace_layout = QHBoxLayout()
widgets = [replace_with, self.replace_text, self.replace_button,
self.all_check]
for widget in widgets:
self.replace_layout.addWidget(widget)
glayout.addLayout(self.replace_layout, 1, 1)
self.widgets.extend(widgets)
self.replace_widgets = widgets
self.hide_replace()
self.search_text.setTabOrder(self.search_text, self.replace_text)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.shortcuts = self.create_shortcuts(parent)
self.highlight_timer = QTimer(self)
self.highlight_timer.setSingleShot(True)
self.highlight_timer.setInterval(1000)
self.highlight_timer.timeout.connect(self.highlight_matches)
示例6: setup
# 需要导入模块: from qtpy.QtWidgets import QGridLayout [as 别名]
# 或者: from qtpy.QtWidgets.QGridLayout import setContentsMargins [as 别名]
def setup(self):
"""Setup the ShortcutEditor with the provided arguments."""
# Widgets
icon_info = HelperToolButton()
icon_info.setIcon(get_std_icon('MessageBoxInformation'))
layout_icon_info = QVBoxLayout()
layout_icon_info.setContentsMargins(0, 0, 0, 0)
layout_icon_info.setSpacing(0)
layout_icon_info.addWidget(icon_info)
layout_icon_info.addStretch(100)
self.label_info = QLabel()
self.label_info.setText(
_("Press the new shortcut and select 'Ok' to confirm, "
"click 'Cancel' to revert to the previous state, "
"or use 'Clear' to unbind the command from a shortcut."))
self.label_info.setAlignment(Qt.AlignTop | Qt.AlignLeft)
self.label_info.setWordWrap(True)
layout_info = QHBoxLayout()
layout_info.setContentsMargins(0, 0, 0, 0)
layout_info.addLayout(layout_icon_info)
layout_info.addWidget(self.label_info)
layout_info.setStretch(1, 100)
self.label_current_sequence = QLabel(_("Current shortcut:"))
self.text_current_sequence = QLabel(self.current_sequence)
self.label_new_sequence = QLabel(_("New shortcut:"))
self.text_new_sequence = ShortcutLineEdit(self)
self.text_new_sequence.setPlaceholderText(_("Press shortcut."))
self.helper_button = HelperToolButton()
self.helper_button.setIcon(QIcon())
self.label_warning = QLabel()
self.label_warning.setWordWrap(True)
self.label_warning.setAlignment(Qt.AlignTop | Qt.AlignLeft)
self.button_default = QPushButton(_('Default'))
self.button_ok = QPushButton(_('Ok'))
self.button_ok.setEnabled(False)
self.button_clear = QPushButton(_('Clear'))
self.button_cancel = QPushButton(_('Cancel'))
button_box = QHBoxLayout()
button_box.addWidget(self.button_default)
button_box.addStretch(100)
button_box.addWidget(self.button_ok)
button_box.addWidget(self.button_clear)
button_box.addWidget(self.button_cancel)
# New Sequence button box
self.btn_clear_sequence = create_toolbutton(
self, icon=ima.icon('editclear'),
tip=_("Clear all entered key sequences"),
triggered=self.clear_new_sequence)
self.button_back_sequence = create_toolbutton(
self, icon=ima.icon('ArrowBack'),
tip=_("Remove last key sequence entered"),
triggered=self.back_new_sequence)
newseq_btnbar = QHBoxLayout()
newseq_btnbar.setSpacing(0)
newseq_btnbar.setContentsMargins(0, 0, 0, 0)
newseq_btnbar.addWidget(self.button_back_sequence)
newseq_btnbar.addWidget(self.btn_clear_sequence)
# Setup widgets
self.setWindowTitle(_('Shortcut: {0}').format(self.name))
self.helper_button.setToolTip('')
style = """
QToolButton {
margin:1px;
border: 0px solid grey;
padding:0px;
border-radius: 0px;
}"""
self.helper_button.setStyleSheet(style)
icon_info.setToolTip('')
icon_info.setStyleSheet(style)
# Layout
layout_sequence = QGridLayout()
layout_sequence.setContentsMargins(0, 0, 0, 0)
layout_sequence.addLayout(layout_info, 0, 0, 1, 4)
layout_sequence.addItem(QSpacerItem(15, 15), 1, 0, 1, 4)
layout_sequence.addWidget(self.label_current_sequence, 2, 0)
layout_sequence.addWidget(self.text_current_sequence, 2, 2)
layout_sequence.addWidget(self.label_new_sequence, 3, 0)
layout_sequence.addWidget(self.helper_button, 3, 1)
layout_sequence.addWidget(self.text_new_sequence, 3, 2)
layout_sequence.addLayout(newseq_btnbar, 3, 3)
layout_sequence.addWidget(self.label_warning, 4, 2, 1, 2)
layout_sequence.setColumnStretch(2, 100)
layout_sequence.setRowStretch(4, 100)
layout = QVBoxLayout()
layout.addLayout(layout_sequence)
layout.addSpacing(5)
layout.addLayout(button_box)
self.setLayout(layout)
#.........这里部分代码省略.........
示例7: setup_page
# 需要导入模块: from qtpy.QtWidgets import QGridLayout [as 别名]
# 或者: from qtpy.QtWidgets.QGridLayout import setContentsMargins [as 别名]
def setup_page(self):
self.ICON = ima.icon('eyedropper')
names = self.get_option("names")
try:
names.pop(names.index(u'Custom'))
except ValueError:
pass
custom_names = self.get_option("custom_names", [])
# Interface options
theme_group = QGroupBox(_("Main interface"))
# Interface Widgets
ui_themes = ['Automatic', 'Light', 'Dark']
ui_theme_choices = list(zip(ui_themes, [ui_theme.lower()
for ui_theme in ui_themes]))
ui_theme_combo = self.create_combobox(_('Interface theme'),
ui_theme_choices,
'ui_theme',
restart=True)
styles = [str(txt) for txt in list(QStyleFactory.keys())]
# Don't offer users the possibility to change to a different
# style in Gtk-based desktops
# Fixes Issue 2036
if is_gtk_desktop() and ('GTK+' in styles):
styles = ['GTK+']
choices = list(zip(styles, [style.lower() for style in styles]))
style_combo = self.create_combobox(_('Qt windows style'), choices,
'windows_style',
default=self.main.default_style)
self.style_combobox = style_combo.combobox
themes = ['Spyder 2', 'Spyder 3']
icon_choices = list(zip(themes, [theme.lower() for theme in themes]))
icons_combo = self.create_combobox(_('Icon theme'), icon_choices,
'icon_theme', restart=True)
theme_comboboxes_layout = QGridLayout()
theme_comboboxes_layout.addWidget(ui_theme_combo.label, 0, 0)
theme_comboboxes_layout.addWidget(ui_theme_combo.combobox, 0, 1)
theme_comboboxes_layout.addWidget(style_combo.label, 1, 0)
theme_comboboxes_layout.addWidget(self.style_combobox, 1, 1)
theme_comboboxes_layout.addWidget(icons_combo.label, 2, 0)
theme_comboboxes_layout.addWidget(icons_combo.combobox, 2, 1)
theme_layout = QVBoxLayout()
theme_layout.addLayout(theme_comboboxes_layout)
theme_group.setLayout(theme_layout)
# Syntax coloring options
syntax_group = QGroupBox(_("Syntax highlighting theme"))
# Syntax Widgets
edit_button = QPushButton(_("Edit selected scheme"))
create_button = QPushButton(_("Create new scheme"))
self.delete_button = QPushButton(_("Delete scheme"))
self.reset_button = QPushButton(_("Reset to defaults"))
self.preview_editor = CodeEditor(self)
self.stacked_widget = QStackedWidget(self)
self.scheme_editor_dialog = SchemeEditor(parent=self,
stack=self.stacked_widget)
self.scheme_choices_dict = {}
schemes_combobox_widget = self.create_combobox('', [('', '')],
'selected')
self.schemes_combobox = schemes_combobox_widget.combobox
# Syntax layout
syntax_layout = QGridLayout(syntax_group)
btns = [self.schemes_combobox, edit_button, self.reset_button,
create_button, self.delete_button]
for i, btn in enumerate(btns):
syntax_layout.addWidget(btn, i, 1)
syntax_layout.setColumnStretch(0, 1)
syntax_layout.setColumnStretch(1, 2)
syntax_layout.setColumnStretch(2, 1)
syntax_layout.setContentsMargins(0, 12, 0, 12)
# Fonts options
fonts_group = QGroupBox(_("Fonts"))
# Fonts widgets
plain_text_font = self.create_fontgroup(
option='font',
title=_("Plain text"),
fontfilters=QFontComboBox.MonospacedFonts,
without_group=True)
rich_text_font = self.create_fontgroup(
option='rich_font',
title=_("Rich text"),
without_group=True)
# Fonts layouts
fonts_layout = QGridLayout()
fonts_layout.addWidget(plain_text_font.fontlabel, 0, 0)
fonts_layout.addWidget(plain_text_font.fontbox, 0, 1)
#.........这里部分代码省略.........