本文整理汇总了Python中AnyQt.QtCore.QSize.isValid方法的典型用法代码示例。如果您正苦于以下问题:Python QSize.isValid方法的具体用法?Python QSize.isValid怎么用?Python QSize.isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtCore.QSize
的用法示例。
在下文中一共展示了QSize.isValid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: IconWidget
# 需要导入模块: from AnyQt.QtCore import QSize [as 别名]
# 或者: from AnyQt.QtCore.QSize import isValid [as 别名]
class IconWidget(QWidget):
"""
A widget displaying an `QIcon`
"""
def __init__(self, parent=None, icon=QIcon(), iconSize=QSize(), **kwargs):
sizePolicy = kwargs.pop("sizePolicy", QSizePolicy(QSizePolicy.Fixed,
QSizePolicy.Fixed))
super().__init__(parent, **kwargs)
self.__icon = QIcon(icon)
self.__iconSize = QSize(iconSize)
self.setSizePolicy(sizePolicy)
def setIcon(self, icon):
# type: (QIcon) -> None
if self.__icon != icon:
self.__icon = QIcon(icon)
self.updateGeometry()
self.update()
def icon(self):
# type: () -> QIcon
return QIcon(self.__icon)
def iconSize(self):
# type: () -> QSize
if not self.__iconSize.isValid():
size = self.style().pixelMetric(QStyle.PM_ButtonIconSize)
return QSize(size, size)
else:
return QSize(self.__iconSize)
def setIconSize(self, iconSize):
# type: (QSize) -> None
if self.__iconSize != iconSize:
self.__iconSize = QSize(iconSize)
self.updateGeometry()
self.update()
def sizeHint(self):
sh = self.iconSize()
m = self.contentsMargins()
return QSize(sh.width() + m.left() + m.right(),
sh.height() + m.top() + m.bottom())
def paintEvent(self, event):
painter = QStylePainter(self)
opt = QStyleOption()
opt.initFrom(self)
painter.drawPrimitive(QStyle.PE_Widget, opt)
if not self.__icon.isNull():
rect = self.contentsRect()
if opt.state & QStyle.State_Active:
mode = QIcon.Active
else:
mode = QIcon.Disabled
self.__icon.paint(painter, rect, Qt.AlignCenter, mode, QIcon.Off)
painter.end()
示例2: ToolBox
# 需要导入模块: from AnyQt.QtCore import QSize [as 别名]
# 或者: from AnyQt.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.Ignored,
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()