本文整理匯總了Python中PyQt5.QtWidgets.QBoxLayout.setContentsMargins方法的典型用法代碼示例。如果您正苦於以下問題:Python QBoxLayout.setContentsMargins方法的具體用法?Python QBoxLayout.setContentsMargins怎麽用?Python QBoxLayout.setContentsMargins使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PyQt5.QtWidgets.QBoxLayout
的用法示例。
在下文中一共展示了QBoxLayout.setContentsMargins方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from PyQt5.QtWidgets import QBoxLayout [as 別名]
# 或者: from PyQt5.QtWidgets.QBoxLayout import setContentsMargins [as 別名]
def __init__(self, actions=None, parent=None,
direction=QBoxLayout.LeftToRight):
QWidget.__init__(self, parent)
self.actions = []
self.buttons = []
layout = QBoxLayout(direction)
layout.setContentsMargins(0, 0, 0, 0)
self.setContentsMargins(0, 0, 0, 0)
self.setLayout(layout)
if actions is not None:
for action in actions:
self.addAction(action)
self.setLayout(layout)
示例2: install_layout_for_widget
# 需要導入模塊: from PyQt5.QtWidgets import QBoxLayout [as 別名]
# 或者: from PyQt5.QtWidgets.QBoxLayout import setContentsMargins [as 別名]
def install_layout_for_widget(widget, orientation=None, margins=None, spacing=None):
"""
Installs a layout to widget, if it does not have it already.
:param widget: target widget
:param orientation: Qt.Vertical (default) / Qt.Horizontal
:param margins: layout margins = (11, 11, 11, 11) from Qt docs, style dependent
:param spacing: spacing between items in layout
:return: None
"""
if widget.layout() is not None:
logger.debug('Widget {0} already has a layout, skipping'.format(widget.windowTitle()))
return # already has a layout
direction = QBoxLayout.TopToBottom
if orientation == Qt.Horizontal:
direction = QBoxLayout.LeftToRight
l = QBoxLayout(direction)
if margins is not None:
l.setContentsMargins(margins[0], margins[1], margins[2], margins[3])
if spacing is not None:
l.setSpacing(spacing)
widget.setLayout(l)
示例3: load_settings_widgets_from_pipeline_groupbox
# 需要導入模塊: from PyQt5.QtWidgets import QBoxLayout [as 別名]
# 或者: from PyQt5.QtWidgets.QBoxLayout import setContentsMargins [as 別名]
def load_settings_widgets_from_pipeline_groupbox(self, position):
"""
Extracts all widgets from a single algorithm and returns a QBoxLayout
Args:
alg: the alg instance we extract from
Returns: a QBoxLayout containing all widgets for this particular alg.
"""
alg = self.pipeline.executed_cats[position].active_algorithm
print("alg " + str(alg))
print("cat " + str(self.pipeline.executed_cats[position]))
empty_flag = True
groupOfSliders = QGroupBox()
sp = QSizePolicy()
sp.setVerticalPolicy(QSizePolicy.Preferred)
# groupOfSliders.setSizePolicy(sp)
groupOfSliderssLayout = QBoxLayout(QBoxLayout.TopToBottom)
groupOfSliderssLayout.setContentsMargins(0, -0, -0, 0)
groupOfSliderssLayout.setAlignment(Qt.AlignTop)
groupOfSliderssLayout.setSpacing(0)
print("Build Slider @ "+ str(position))
# create integer sliders
for slider in alg.integer_sliders:
empty_flag = False
print("slider.value " + str(slider.value))
print("slider " + str(slider))
#print(alg.get_name() + ": add slider (int).")
groupOfSliderssLayout.addWidget(
SliderWidget(slider.name, slider.lower, slider.upper, slider.step_size, slider.value,
slider.set_value, False))
# create float sliders
for slider in alg.float_sliders:
empty_flag = False
#print(alg.get_name() + ": add slider (float).")
groupOfSliderssLayout.addWidget(
SliderWidget(slider.name, slider.lower, slider.upper, slider.step_size, slider.value,
slider.set_value, True), 0, Qt.AlignTop)
# create checkboxes
for checkbox in alg.checkboxes:
empty_flag = False
#print(alg.get_name() + ": add checkbox.")
groupOfSliderssLayout.addWidget(CheckBoxWidget(checkbox.name, checkbox.value, checkbox.set_value), 0,
Qt.AlignTop)
# create dropdowns
for combobox in alg.drop_downs:
empty_flag = False
#print(alg.get_name() + ": add combobox.")
groupOfSliderssLayout.addWidget(
ComboBoxWidget(combobox.name, combobox.options, combobox.set_value, combobox.value), 0, Qt.AlignTop)
if empty_flag:
label = QLabel()
label.setText("This algorithm has no Settings.")
groupOfSliderssLayout.addWidget(label, 0, Qt.AlignHCenter)
groupOfSliders.setLayout(groupOfSliderssLayout)
return groupOfSliders
示例4: E5SideBar
# 需要導入模塊: from PyQt5.QtWidgets import QBoxLayout [as 別名]
# 或者: from PyQt5.QtWidgets.QBoxLayout import setContentsMargins [as 別名]
class E5SideBar(QWidget):
"""
Class implementing a sidebar with a widget area, that is hidden or shown,
if the current tab is clicked again.
"""
Version = 1
North = 0
East = 1
South = 2
West = 3
def __init__(self, orientation=None, delay=200, parent=None):
"""
Constructor
@param orientation orientation of the sidebar widget (North, East,
South, West)
@param delay value for the expand/shrink delay in milliseconds
(integer)
@param parent parent widget (QWidget)
"""
super(E5SideBar, self).__init__(parent)
self.__tabBar = QTabBar()
self.__tabBar.setDrawBase(True)
self.__tabBar.setShape(QTabBar.RoundedNorth)
self.__tabBar.setUsesScrollButtons(True)
self.__tabBar.setDrawBase(False)
self.__stackedWidget = QStackedWidget(self)
self.__stackedWidget.setContentsMargins(0, 0, 0, 0)
self.__autoHideButton = QToolButton()
self.__autoHideButton.setCheckable(True)
self.__autoHideButton.setIcon(
UI.PixmapCache.getIcon("autoHideOff.png"))
self.__autoHideButton.setChecked(True)
self.__autoHideButton.setToolTip(
self.tr("Deselect to activate automatic collapsing"))
self.barLayout = QBoxLayout(QBoxLayout.LeftToRight)
self.barLayout.setContentsMargins(0, 0, 0, 0)
self.layout = QBoxLayout(QBoxLayout.TopToBottom)
self.layout.setContentsMargins(0, 0, 0, 0)
self.layout.setSpacing(0)
self.barLayout.addWidget(self.__autoHideButton)
self.barLayout.addWidget(self.__tabBar)
self.layout.addLayout(self.barLayout)
self.layout.addWidget(self.__stackedWidget)
self.setLayout(self.layout)
# initialize the delay timer
self.__actionMethod = None
self.__delayTimer = QTimer(self)
self.__delayTimer.setSingleShot(True)
self.__delayTimer.setInterval(delay)
self.__delayTimer.timeout.connect(self.__delayedAction)
self.__minimized = False
self.__minSize = 0
self.__maxSize = 0
self.__bigSize = QSize()
self.splitter = None
self.splitterSizes = []
self.__hasFocus = False
# flag storing if this widget or any child has the focus
self.__autoHide = False
self.__tabBar.installEventFilter(self)
self.__orientation = E5SideBar.North
if orientation is None:
orientation = E5SideBar.North
self.setOrientation(orientation)
self.__tabBar.currentChanged[int].connect(
self.__stackedWidget.setCurrentIndex)
e5App().focusChanged[QWidget, QWidget].connect(self.__appFocusChanged)
self.__autoHideButton.toggled[bool].connect(self.__autoHideToggled)
def setSplitter(self, splitter):
"""
Public method to set the splitter managing the sidebar.
@param splitter reference to the splitter (QSplitter)
"""
self.splitter = splitter
self.splitter.splitterMoved.connect(self.__splitterMoved)
self.splitter.setChildrenCollapsible(False)
index = self.splitter.indexOf(self)
self.splitter.setCollapsible(index, False)
def __splitterMoved(self, pos, index):
"""
Private slot to react on splitter moves.
@param pos new position of the splitter handle (integer)
@param index index of the splitter handle (integer)
"""
if self.splitter:
#.........這裏部分代碼省略.........
示例5: QWidget
# 需要導入模塊: from PyQt5.QtWidgets import QBoxLayout [as 別名]
# 或者: from PyQt5.QtWidgets.QBoxLayout import setContentsMargins [as 別名]
window = QWidget()
btn1 = QPushButton("One")
btn2 = QPushButton("Two")
btn3 = QPushButton("Three")
# Set the layout
box = QBoxLayout(QBoxLayout.Direction(0)) # TODO
box.addWidget(btn1)
box.addWidget(btn2)
box.addWidget(btn3)
box.setContentsMargins(0, 0, 0, 0) # set the spacing around the layout (in pixels)
box.setSpacing(0) # set the spacing between elements (in pixels)
window.setLayout(box)
# Show
window.show()
# The mainloop of the application. The event handling starts from this point.
# The exec_() method has an underscore. It is because the exec is a Python keyword. And thus, exec_() was used instead.
exit_code = app.exec_()
# The sys.exit() method ensures a clean exit.
# The environment will be informed, how the application ended.
sys.exit(exit_code)