本文整理汇总了Python中PyQt4.QtGui.QBoxLayout.setMargin方法的典型用法代码示例。如果您正苦于以下问题:Python QBoxLayout.setMargin方法的具体用法?Python QBoxLayout.setMargin怎么用?Python QBoxLayout.setMargin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QBoxLayout
的用法示例。
在下文中一共展示了QBoxLayout.setMargin方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: QPageWidget
# 需要导入模块: from PyQt4.QtGui import QBoxLayout [as 别名]
# 或者: from PyQt4.QtGui.QBoxLayout import setMargin [as 别名]
class QPageWidget(QScrollArea):
""" The QPageWidget provides a stack widget with animated page transitions. """
def __init__(self, parent = None, direction = "ltr", rtf = False):
""" Creates a new QPageWidget on given parent object.
parent: QWidget parent
direction: "ltr" -> Left To Right
"ttb" -> Top To Bottom
rtf: Return to first, if its True it flips to the first page
when next page requested at the last page
"""
# First initialize, QPageWidget is based on QScrollArea
QScrollArea.__init__(self, parent)
# Properties for QScrollArea
self.setFrameShape(QFrame.NoFrame)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setWidgetResizable(True)
# Main widget, which stores all Pages in it
self.widget = QWidget(self)
# Layout based on QBoxLayout which supports Vertical or Horizontal layout
if direction == "ltr":
self.layout = QBoxLayout(QBoxLayout.LeftToRight, self.widget)
self.__scrollBar = self.horizontalScrollBar()
self.__base_value = self.width
else:
self.layout = QBoxLayout(QBoxLayout.TopToBottom, self.widget)
self.__scrollBar = self.verticalScrollBar()
self.__base_value = self.height
self.layout.setSpacing(0)
self.layout.setMargin(0)
# Return to first
self.__return_to_first = rtf
# TMP_PAGE, its using as last page in stack
# A workaround for a QScrollArea bug
self.__tmp_page = Page(QWidget(self.widget))
self.__pages = [self.__tmp_page]
self.__current = 0
self.__last = 0
# Set main widget
self.setWidget(self.widget)
# Animation TimeLine
self.__timeline = QTimeLine()
self.__timeline.setUpdateInterval(2)
# Updates scrollbar position when frame changed
self.__timeline.frameChanged.connect(lambda x: self.__scrollBar.setValue(x))
# End of the animation
self.__timeline.finished.connect(self._animateFinished)
# Initialize animation
self.setAnimation()
self.setDuration()
def _animateFinished(self):
""" Its called by TimeLine when animation finished.
It first runs the outMethod of last Page and then the inMethod of current Page
Finally tt gives the focus to the current page and fixes the scrollBar
"""
# Disable other widgets
for page in self.__pages:
if not page == self.__pages[self.__current]:
page.widget.setEnabled(False)
# Run last page's outMethod if exists
if self.__pages[self.__last].outMethod:
self.__pages[self.__last].outMethod()
# Run new page's inMethod if exists
if self.__pages[self.__current].inMethod:
self.__pages[self.__current].inMethod()
# Give focus to the current Page
self.__pages[self.__current].widget.setFocus()
# Update scrollbar position for current page
self.__scrollBar.setValue(self.__current * self.__base_value())
# Emit currentChanged SIGNAL
self.emit(SIGNAL("currentChanged()"))
def event(self, event):
""" Overrides the main event handler to catch resize events """
# Catch Resize event
if event.type() == QEvent.Resize:
# Update each page size limits to mainwidget's new size
for page in self.__pages:
page.widget.setMinimumSize(self.size())
page.widget.setMaximumSize(self.size())
#.........这里部分代码省略.........
示例2: E4SideBar
# 需要导入模块: from PyQt4.QtGui import QBoxLayout [as 别名]
# 或者: from PyQt4.QtGui.QBoxLayout import setMargin [as 别名]
class E4SideBar(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)
"""
QWidget.__init__(self, 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.trUtf8("Deselect to activate automatic collapsing"))
self.barLayout = QBoxLayout(QBoxLayout.LeftToRight)
self.barLayout.setMargin(0)
self.layout = QBoxLayout(QBoxLayout.TopToBottom)
self.layout.setMargin(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.connect(self.__delayTimer, SIGNAL("timeout()"), 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 = E4SideBar.North
if orientation is None:
orientation = E4SideBar.North
self.setOrientation(orientation)
self.connect(self.__tabBar, SIGNAL("currentChanged(int)"),
self.__stackedWidget, SLOT("setCurrentIndex(int)"))
self.connect(e4App(), SIGNAL("focusChanged(QWidget*, QWidget*)"),
self.__appFocusChanged)
self.connect(self.__autoHideButton, SIGNAL("toggled(bool)"),
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.connect(self.splitter, SIGNAL("splitterMoved(int, int)"),
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:
self.splitterSizes = self.splitter.sizes()
#.........这里部分代码省略.........
示例3: SideBar
# 需要导入模块: from PyQt4.QtGui import QBoxLayout [as 别名]
# 或者: from PyQt4.QtGui.QBoxLayout import setMargin [as 别名]
class SideBar( QWidget ):
""" Sidebar with a widget area which is hidden or shown.
On by clicking any tab, off by clicking the current tab.
"""
North = 0
East = 1
South = 2
West = 3
def __init__( self, orientation = 2, parent = None ):
QWidget.__init__( self, parent )
self.__tabBar = QTabBar()
self.__tabBar.setDrawBase( True )
self.__tabBar.setShape( QTabBar.RoundedNorth )
self.__tabBar.setFocusPolicy( Qt.NoFocus )
self.__tabBar.setUsesScrollButtons( True )
self.__tabBar.setElideMode( 1 )
self.__stackedWidget = QStackedWidget( self )
self.__stackedWidget.setContentsMargins( 0, 0, 0, 0 )
self.barLayout = QBoxLayout( QBoxLayout.LeftToRight )
self.barLayout.setMargin( 0 )
self.layout = QBoxLayout( QBoxLayout.TopToBottom )
self.layout.setMargin( 0 )
self.layout.setSpacing( 0 )
self.barLayout.addWidget( self.__tabBar )
self.layout.addLayout( self.barLayout )
self.layout.addWidget( self.__stackedWidget )
self.setLayout( self.layout )
self.__minimized = False
self.__minSize = 0
self.__maxSize = 0
self.__bigSize = QSize()
self.splitter = None
self.__tabBar.installEventFilter( self )
self.__orientation = orientation
self.setOrientation( orientation )
self.__tabBar.currentChanged.connect(
self.__stackedWidget.setCurrentIndex )
return
def setSplitter( self, splitter ):
""" Set the splitter managing the sidebar """
self.splitter = splitter
return
def __getIndex( self ):
" Provides the widget index in splitters "
if self.__orientation == SideBar.West:
return 0
if self.__orientation == SideBar.East:
return 2
if self.__orientation == SideBar.South:
return 1
return 0
def __getWidget( self ):
" Provides a reference to the widget "
return self.splitter.widget( self.__getIndex() )
def shrink( self ):
""" Shrink the sidebar """
if self.__minimized:
return
self.__minimized = True
self.__bigSize = self.size()
if self.__orientation in [ SideBar.North, SideBar.South ]:
self.__minSize = self.minimumHeight()
self.__maxSize = self.maximumHeight()
else:
self.__minSize = self.minimumWidth()
self.__maxSize = self.maximumWidth()
self.__stackedWidget.hide()
sizes = self.splitter.sizes()
selfIndex = self.__getIndex()
if self.__orientation in [ SideBar.North, SideBar.South ]:
newHeight = self.__tabBar.minimumSizeHint().height()
self.setFixedHeight( newHeight )
diff = sizes[ selfIndex ] - newHeight
sizes[ selfIndex ] = newHeight
else:
newWidth = self.__tabBar.minimumSizeHint().width()
self.setFixedWidth( newWidth )
diff = sizes[ selfIndex ] - newWidth
sizes[ selfIndex ] = newWidth
if selfIndex == 0:
sizes[ 1 ] += diff
#.........这里部分代码省略.........