本文整理汇总了Python中AnyQt.QtCore.QSize类的典型用法代码示例。如果您正苦于以下问题:Python QSize类的具体用法?Python QSize怎么用?Python QSize使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QSize类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __updatePixmap
def __updatePixmap(self):
"""
Update the cached shadow pixmap.
"""
rect_size = QSize(50, 50)
left = top = right = bottom = self.radius_
# Size of the pixmap.
pixmap_size = QSize(rect_size.width() + left + right,
rect_size.height() + top + bottom)
shadow_rect = QRect(QPoint(left, top), rect_size)
pixmap = QPixmap(pixmap_size)
pixmap.fill(QColor(0, 0, 0, 0))
rect_fill_color = self.palette().color(QPalette.Window)
pixmap = render_drop_shadow_frame(
pixmap,
QRectF(shadow_rect),
shadow_color=self.color_,
offset=QPointF(0, 0),
radius=self.radius_,
rect_fill_color=rect_fill_color
)
self.__shadowPixmap = pixmap
self.update()
示例2: sizeHint
def sizeHint(self):
"""
Reimplemented from `QPushButton.sizeHint`.
Returns
-------
sh : QSize
"""
sh = super().sizeHint()
option = QStyleOptionButton()
self.initStyleOption(option)
style = self.style()
fm = option.fontMetrics
if option.iconSize.isValid():
icsize = option.iconSize
icsize.setWidth(icsize.width() + 4)
else:
icsize = QSize()
for text in self.__textChoiceList:
option.text = text
size = fm.size(Qt.TextShowMnemonic, text)
if not icsize.isNull():
size.setWidth(size.width() + icsize.width())
size.setHeight(max(size.height(), icsize.height()))
sh = sh.expandedTo(
style.sizeFromContents(QStyle.CT_PushButton, option,
size, self))
return sh
示例3: sizeHint
def sizeHint(self, option, index):
size = QStyledItemDelegate.sizeHint(self, option, index)
parent = self.parent()
item = parent.itemFromIndex(index)
widget = parent.itemWidget(item, 0)
if widget:
size = QSize(size.width(), widget.sizeHint().height() / 2)
return size
示例4: sizeHint
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)
示例5: __init__
def __init__(self, parent=None, icon=None, iconSize=None, **kwargs):
QGraphicsItem.__init__(self, parent, **kwargs)
self.setFlag(QGraphicsItem.ItemUsesExtendedStyleOption, True)
if icon is None:
icon = QIcon()
if iconSize is None:
style = QApplication.instance().style()
size = style.pixelMetric(style.PM_LargeIconSize)
iconSize = QSize(size, size)
self.__transformationMode = Qt.SmoothTransformation
self.__iconSize = QSize(iconSize)
self.__icon = QIcon(icon)
self._opacity = 1
self.anim = QPropertyAnimation(self, b"opacity")
self.anim.setDuration(350)
self.anim.setStartValue(1)
self.anim.setKeyValueAt(0.5, 0)
self.anim.setEndValue(1)
self.anim.setEasingCurve(QEasingCurve.OutQuad)
self.anim.setLoopCount(5)
示例6: __init__
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)
示例7: setIconSize
def setIconSize(self, size):
"""
Set the icon (and this item's) size (:class:`QSize`).
"""
if self.__iconSize != size:
self.prepareGeometryChange()
self.__iconSize = QSize(size)
self.update()
示例8: __init__
def __init__(self, parent=None, **kwargs):
super().__init__(parent, **kwargs)
self.__pages = []
self.__tabButtonHeight = -1
self.__tabIconSize = QSize()
self.__exclusive = False
self.__setupUi()
示例9: IconWidget
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()
示例10: __layoutActions
def __layoutActions(self):
left, right = self.__actions
contents = self.contentsRect()
buttonSize = QSize(contents.height(), contents.height())
margins = self.textMargins()
if left:
geom = QRect(contents.topLeft(), buttonSize)
left.button.setGeometry(geom)
margins.setLeft(buttonSize.width())
if right:
geom = QRect(contents.topRight(), buttonSize)
right.button.setGeometry(geom.translated(-buttonSize.width(), 0))
margins.setLeft(buttonSize.width())
self.setTextMargins(margins)
示例11: _updateShadowPixmap
def _updateShadowPixmap(self):
"""Update the cached drop shadow pixmap.
"""
# Rectangle casting the shadow
rect_size = QSize(*CACHED_SHADOW_RECT_SIZE)
left, top, right, bottom = self.getContentsMargins()
# Size of the pixmap.
pixmap_size = QSize(rect_size.width() + left + right,
rect_size.height() + top + bottom)
shadow_rect = QRect(QPoint(left, top), rect_size)
pixmap = QPixmap(pixmap_size)
pixmap.fill(QColor(0, 0, 0, 0))
rect_fill_color = self.palette().color(QPalette.Window)
pixmap = render_drop_shadow_frame(pixmap, QRectF(shadow_rect),
shadow_color=self.color,
offset=self.offset,
radius=self.radius,
rect_fill_color=rect_fill_color)
self._shadowPixmap = pixmap
示例12: __init__
def __init__(self, parent=None, icon=None, iconSize=None, **kwargs):
QGraphicsItem.__init__(self, parent, **kwargs)
self.setFlag(QGraphicsItem.ItemUsesExtendedStyleOption, True)
if icon is None:
icon = QIcon()
if iconSize is None:
style = QApplication.instance().style()
size = style.pixelMetric(style.PM_LargeIconSize)
iconSize = QSize(size, size)
self.__transformationMode = Qt.SmoothTransformation
self.__iconSize = QSize(iconSize)
self.__icon = QIcon(icon)
示例13: GraphicsIconItem
class GraphicsIconItem(QGraphicsItem):
"""
A graphics item displaying an :class:`QIcon`.
"""
def __init__(self, parent=None, icon=None, iconSize=None, **kwargs):
QGraphicsItem.__init__(self, parent, **kwargs)
self.setFlag(QGraphicsItem.ItemUsesExtendedStyleOption, True)
if icon is None:
icon = QIcon()
if iconSize is None:
style = QApplication.instance().style()
size = style.pixelMetric(style.PM_LargeIconSize)
iconSize = QSize(size, size)
self.__transformationMode = Qt.SmoothTransformation
self.__iconSize = QSize(iconSize)
self.__icon = QIcon(icon)
def setIcon(self, icon):
"""
Set the icon (:class:`QIcon`).
"""
if self.__icon != icon:
self.__icon = QIcon(icon)
self.update()
def icon(self):
"""
Return the icon (:class:`QIcon`).
"""
return QIcon(self.__icon)
def setIconSize(self, size):
"""
Set the icon (and this item's) size (:class:`QSize`).
"""
if self.__iconSize != size:
self.prepareGeometryChange()
self.__iconSize = QSize(size)
self.update()
def iconSize(self):
"""
Return the icon size (:class:`QSize`).
"""
return QSize(self.__iconSize)
def setTransformationMode(self, mode):
"""
Set pixmap transformation mode. (`Qt.SmoothTransformation` or
`Qt.FastTransformation`).
"""
if self.__transformationMode != mode:
self.__transformationMode = mode
self.update()
def transformationMode(self):
"""
Return the pixmap transformation mode.
"""
return self.__transformationMode
def boundingRect(self):
return QRectF(0, 0, self.__iconSize.width(), self.__iconSize.height())
def paint(self, painter, option, widget=None):
if not self.__icon.isNull():
if option.state & QStyle.State_Selected:
mode = QIcon.Selected
elif option.state & QStyle.State_Enabled:
mode = QIcon.Normal
elif option.state & QStyle.State_Active:
mode = QIcon.Active
else:
mode = QIcon.Disabled
transform = self.sceneTransform()
if widget is not None:
# 'widget' is the QGraphicsView.viewport()
view = widget.parent()
if isinstance(view, QGraphicsView):
# Combine the scene transform with the view transform.
view_transform = view.transform()
transform = view_transform * view_transform
lod = option.levelOfDetailFromTransform(transform)
w, h = self.__iconSize.width(), self.__iconSize.height()
target = QRectF(0, 0, w, h)
source = QRectF(0, 0, w * lod, w * lod).toRect()
# The actual size of the requested pixmap can be smaller.
size = self.__icon.actualSize(source.size(), mode=mode)
source.setSize(size)
#.........这里部分代码省略.........
示例14: GraphicsIconItem
class GraphicsIconItem(QGraphicsItem):
"""
A graphics item displaying an :class:`QIcon`.
"""
def __init__(self, parent=None, icon=None, iconSize=None, **kwargs):
QGraphicsItem.__init__(self, parent, **kwargs)
self.setFlag(QGraphicsItem.ItemUsesExtendedStyleOption, True)
if icon is None:
icon = QIcon()
if iconSize is None:
style = QApplication.instance().style()
size = style.pixelMetric(style.PM_LargeIconSize)
iconSize = QSize(size, size)
self.__transformationMode = Qt.SmoothTransformation
self.__iconSize = QSize(iconSize)
self.__icon = QIcon(icon)
def setIcon(self, icon):
"""
Set the icon (:class:`QIcon`).
"""
if self.__icon != icon:
self.__icon = QIcon(icon)
self.update()
def icon(self):
"""
Return the icon (:class:`QIcon`).
"""
return QIcon(self.__icon)
def setIconSize(self, size):
"""
Set the icon (and this item's) size (:class:`QSize`).
"""
if self.__iconSize != size:
self.prepareGeometryChange()
self.__iconSize = QSize(size)
self.update()
def iconSize(self):
"""
Return the icon size (:class:`QSize`).
"""
return QSize(self.__iconSize)
def setTransformationMode(self, mode):
"""
Set pixmap transformation mode. (`Qt.SmoothTransformation` or
`Qt.FastTransformation`).
"""
if self.__transformationMode != mode:
self.__transformationMode = mode
self.update()
def transformationMode(self):
"""
Return the pixmap transformation mode.
"""
return self.__transformationMode
def boundingRect(self):
return QRectF(0, 0, self.__iconSize.width(), self.__iconSize.height())
def paint(self, painter, option, widget=None):
if not self.__icon.isNull():
if option.state & QStyle.State_Selected:
mode = QIcon.Selected
elif option.state & QStyle.State_Enabled:
mode = QIcon.Normal
elif option.state & QStyle.State_Active:
mode = QIcon.Active
else:
mode = QIcon.Disabled
w, h = self.__iconSize.width(), self.__iconSize.height()
target = QRect(0, 0, w, h)
painter.setRenderHint(
QPainter.SmoothPixmapTransform,
self.__transformationMode == Qt.SmoothTransformation
)
self.__icon.paint(painter, target, Qt.AlignCenter, mode)
示例15: sizeHint
def sizeHint(self, option, index):
size = QStyledItemDelegate.sizeHint(self, option, index)
size = QSize(size.width(), size.height() + 4)
return size