本文整理汇总了Python中PyQt4.QtCore.QSize.isValid方法的典型用法代码示例。如果您正苦于以下问题:Python QSize.isValid方法的具体用法?Python QSize.isValid怎么用?Python QSize.isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore.QSize
的用法示例。
在下文中一共展示了QSize.isValid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: QFlowWidgetItem
# 需要导入模块: from PyQt4.QtCore import QSize [as 别名]
# 或者: from PyQt4.QtCore.QSize import isValid [as 别名]
class QFlowWidgetItem(QWidgetItem):
""" A custom QWidgetItem for use with the QFlowLayout.
"""
#: The FlowLayoutData associated with this widget item. It is a
#: publically accesible attribute for performance reasons.
data = None
def __init__(self, widget, data):
""" Initialize a QFlowWidgetItem.
Parameters
----------
widget : QWidget
The widget to manage with this item.
data : FlowLayoutData
The layout data struct associated with this item.
"""
super(QFlowWidgetItem, self).__init__(widget)
self.data = data
self._cached_hint = QSize()
self._cached_max = QSize()
self._cached_min = QSize()
def maximumSize(self):
""" Reimplemented maximum size computation.
The max size for a flow widget item is cached and recomputed
only when the widget item is invalidated.
"""
if not self._cached_max.isValid():
self._cached_max = super(QFlowWidgetItem, self).maximumSize()
return self._cached_max
def minimumSize(self):
""" Reimplemented minimum size computation.
The min size for a flow widget item is cached and recomputed
only when the widget item is invalidated.
"""
if not self._cached_min.isValid():
self._cached_min = super(QFlowWidgetItem, self).minimumSize()
return self._cached_min
def sizeHint(self):
""" Reimplemented size hint computation.
The size hint for a flow widget item is cached and recomputed
only when the widget item is invalidated. The size hint is the
valid union of the preferred size, as indicated by the layout
data, and the size hint of the widget.
"""
if not self._cached_hint.isValid():
hint = super(QFlowWidgetItem, self).sizeHint()
pref = self.data.preferred_size
smin = self.minimumSize()
smax = self.maximumSize()
if pref.width() != -1:
pw = max(smin.width(), min(pref.width(), smax.width()))
hint.setWidth(pw)
if pref.height() != -1:
ph = max(smin.height(), min(pref.height(), smax.height()))
hint.setHeight(ph)
self._cached_hint = hint
return self._cached_hint
def setGeometry(self, rect):
""" Set the rectangle covered by this layout item.
This reimplemented method ensures that layout always occurs at
the origin of the given rect. The default QWidgetItem behavior
is to center the item in the given space.
Parameters
----------
rect : QRect
The rectangle that this layout item should cover.
"""
if self.isEmpty():
return
s = rect.size().boundedTo(self.maximumSize())
self.widget().setGeometry(rect.x(), rect.y(), s.width(), s.height())
def invalidate(self):
""" Invalidate the internal cached data for this widget item.
The invalidation will only have an effect if the layout data
associate with this item is marked as dirty.
"""
if self.data.dirty:
self._cached_hint = QSize()
self._cached_min = QSize()
self.data.dirty = False
示例2: ToolBox
# 需要导入模块: from PyQt4.QtCore import QSize [as 别名]
# 或者: from PyQt4.QtCore.QSize import isValid [as 别名]
#.........这里部分代码省略.........
"""
Return the number of widgets inserted in the toolbox.
"""
return len(self.__pages)
def widget(self, index):
"""
Return the widget at `index`.
"""
return self.__pages[index].widget
def createTabButton(self, widget, text, icon=None, toolTip=None):
"""
Create the tab button for `widget`.
"""
action = QAction(text, self)
action.setCheckable(True)
if icon:
action.setIcon(icon)
if toolTip:
action.setToolTip(toolTip)
self.__tabActionGroup.addAction(action)
self.__actionMapper.setMapping(action, action)
action.toggled.connect(self.__actionMapper.map)
button = ToolBoxTabButton(self, objectName="toolbox-tab-button")
button.setDefaultAction(action)
button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
button.setSizePolicy(QSizePolicy.Expanding,
QSizePolicy.Fixed)
if self.__tabIconSize.isValid():
button.setIconSize(self.__tabIconSize)
if self.__tabButtonHeight > 0:
button.setFixedHeight(self.__tabButtonHeight)
return button
def ensureWidgetVisible(self, child, xmargin=50, ymargin=50):
"""
Scroll the contents so child widget instance is visible inside
the viewport.
"""
self.__scrollArea.ensureWidgetVisible(child, xmargin, ymargin)
def sizeHint(self):
hint = self.__contentsLayout.sizeHint()
if self.count():
# Compute max width of hidden widgets also.
scroll = self.__scrollArea
scroll_w = scroll.verticalScrollBar().sizeHint().width()
frame_w = self.frameWidth() * 2 + scroll.frameWidth() * 2
max_w = max([p.widget.sizeHint().width() for p in self.__pages])
hint = QSize(max(max_w, hint.width()) + scroll_w + frame_w,
hint.height())
return QSize(200, 200).expandedTo(hint)
def __onTabActionToogled(self, action):
page = find(self.__pages, action, key=attrgetter("action"))
on = action.isChecked()