本文整理汇总了Python中PyQt4.QtGui.QGraphicsGridLayout.setContentsMargins方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsGridLayout.setContentsMargins方法的具体用法?Python QGraphicsGridLayout.setContentsMargins怎么用?Python QGraphicsGridLayout.setContentsMargins使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QGraphicsGridLayout
的用法示例。
在下文中一共展示了QGraphicsGridLayout.setContentsMargins方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from PyQt4.QtGui import QGraphicsGridLayout [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsGridLayout import setContentsMargins [as 别名]
def __init__(self, parent=None):
QGraphicsWidget.__init__(self, parent)
self.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
self.setContentsMargins(10, 10, 10, 10)
layout = QGraphicsGridLayout()
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(10)
self.setLayout(layout)
示例2: GraphicsThumbnailGrid
# 需要导入模块: from PyQt4.QtGui import QGraphicsGridLayout [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsGridLayout import setContentsMargins [as 别名]
class GraphicsThumbnailGrid(QGraphicsWidget):
class LayoutMode(enum.Enum):
FixedColumnCount, AutoReflow = 0, 1
FixedColumnCount, AutoReflow = LayoutMode
#: Signal emitted when the current (thumbnail) changes
currentThumbnailChanged = Signal(object)
def __init__(self, parent=None, **kwargs):
super().__init__(parent, **kwargs)
self.__layoutMode = GraphicsThumbnailGrid.AutoReflow
self.__columnCount = -1
self.__thumbnails = [] # type: List[GraphicsThumbnailWidget]
#: The current 'focused' thumbnail item. This is the item that last
#: received the keyboard focus (though it does not necessarily have
#: it now)
self.__current = None # type: Optional[GraphicsThumbnailWidget]
self.__reflowPending = False
self.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
self.setContentsMargins(10, 10, 10, 10)
# NOTE: Keeping a reference to the layout. self.layout()
# returns a QGraphicsLayout wrapper (i.e. strips the
# QGraphicsGridLayout-nes of the object).
self.__layout = QGraphicsGridLayout()
self.__layout.setContentsMargins(0, 0, 0, 0)
self.__layout.setSpacing(10)
self.setLayout(self.__layout)
def resizeEvent(self, event):
super().resizeEvent(event)
if event.newSize().width() != event.oldSize().width() and \
self.__layoutMode == GraphicsThumbnailGrid.AutoReflow:
self.__reflow()
def setGeometry(self, rect):
self.prepareGeometryChange()
super().setGeometry(rect)
def count(self):
"""
Returns
-------
count: int
Number of thumbnails in the widget
"""
return len(self.__thumbnails)
def addThumbnail(self, thumbnail):
"""
Add/append a thumbnail to the widget
Parameters
----------
thumbnail: Union[GraphicsThumbnailWidget, QPixmap]
The thumbnail to insert
"""
self.insertThumbnail(self.count(), thumbnail)
def insertThumbnail(self, index, thumbnail):
"""
Insert a new thumbnail into a widget.
Raise a ValueError if thumbnail is already in the view.
Parameters
----------
index : int
Index where to insert
thumbnail : Union[GraphicsThumbnailWidget, QPixmap]
The thumbnail to insert. GraphicsThumbnailGrid takes ownership
of the item.
"""
if isinstance(thumbnail, QPixmap):
thumbnail = GraphicsThumbnailWidget(thumbnail, parentItem=self)
elif thumbnail in self.__thumbnails:
raise ValueError("{!r} is already inserted".format(thumbnail))
elif not isinstance(thumbnail, GraphicsThumbnailWidget):
raise TypeError
index = max(min(index, self.count()), 0)
moved = self.__takeItemsFrom(index)
assert moved == self.__thumbnails[index:]
self.__thumbnails.insert(index, thumbnail)
self.__appendItems([thumbnail] + moved)
thumbnail.setParentItem(self)
thumbnail.installEventFilter(self)
assert self.count() == self.layout().count()
self.__scheduleLayout()
def removeThumbnail(self, thumbnail):
"""
Remove a single thumbnail from the grid.
Raise a ValueError if thumbnail is not in the grid.
#.........这里部分代码省略.........