本文整理汇总了Python中PyQt5.QtCore.QSize类的典型用法代码示例。如果您正苦于以下问题:Python QSize类的具体用法?Python QSize怎么用?Python QSize使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QSize类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: calculate_relative_position
def calculate_relative_position(parent_rect: QtCore.QRect, own_size: QtCore.QSize,
constraint: RelativeLayoutConstraint):
"""
Calculates the position of the element, given its size, the position and size of the parent and a relative layout
constraint. The position is the position of the parent plus the weighted size of the parent, the weighted size of
the element and an offset. The weights and the offset are given by the constraint for each direction.
:param parent_rect: parent coordinates and size as rectangle
:param own_size: size of the element (width and height)
:param constraint: relative layout constraint to apply
:return: tuple of recommended x and y positions of the element
"""
"""
Returns the left, upper corner of an object if the parent rectangle (QRect) is given and our own size (QSize)
and a relative layout constraint (see RelativeLayoutConstraint).
"""
x = (parent_rect.x()
+ constraint.x[0] * parent_rect.width()
+ constraint.x[1] * own_size.width()
+ constraint.x[2])
y = (parent_rect.y()
+ constraint.y[0] * parent_rect.height()
+ constraint.y[1] * own_size.height()
+ constraint.y[2])
return x, y
示例2: _get_icon_rect
def _get_icon_rect(self, opt, text_rect):
"""Get a QRect for the icon to draw.
Args:
opt: QStyleOptionTab
text_rect: The QRect for the text.
Return:
A QRect.
"""
icon_size = opt.iconSize
if not icon_size.isValid():
icon_extent = self.pixelMetric(QStyle.PM_SmallIconSize)
icon_size = QSize(icon_extent, icon_extent)
icon_mode = (QIcon.Normal if opt.state & QStyle.State_Enabled
else QIcon.Disabled)
icon_state = (QIcon.On if opt.state & QStyle.State_Selected
else QIcon.Off)
# reserve space for favicon when tab bar is vertical (issue #1968)
position = config.val.tabs.position
if (position in [QTabWidget.East, QTabWidget.West] and
config.val.tabs.favicons.show):
tab_icon_size = icon_size
else:
actual_size = opt.icon.actualSize(icon_size, icon_mode, icon_state)
tab_icon_size = QSize(
min(actual_size.width(), icon_size.width()),
min(actual_size.height(), icon_size.height()))
icon_top = text_rect.center().y() + 1 - tab_icon_size.height() / 2
icon_rect = QRect(QPoint(text_rect.left(), icon_top), tab_icon_size)
icon_rect = self._style.visualRect(opt.direction, opt.rect, icon_rect)
return icon_rect
示例3: set_viewport
def set_viewport(self, size, raise_if_empty=False):
"""
Set viewport size.
If size is "full" viewport size is detected automatically.
If can also be "<width>x<height>".
.. note::
This will update all JS geometry variables, but window resize event
is delivered asynchronously and so ``window.resize`` will not be
invoked until control is yielded to the event loop.
"""
if size == 'full':
size = self.web_page.mainFrame().contentsSize()
self.logger.log("Contents size: %s" % size, min_level=2)
if size.isEmpty():
if raise_if_empty:
raise RuntimeError("Cannot detect viewport size")
else:
size = defaults.VIEWPORT_SIZE
self.logger.log("Viewport is empty, falling back to: %s" %
size)
if not isinstance(size, QSize):
validate_size_str(size)
w, h = map(int, size.split('x'))
size = QSize(w, h)
self.web_page.setViewportSize(size)
self._force_relayout()
w, h = int(size.width()), int(size.height())
self.logger.log("viewport size is set to %sx%s" % (w, h), min_level=2)
return w, h
示例4: get_favicon
def get_favicon(self):
u"""
Get favicon for the site.
This is called when the site_url can’t be loaded or when that
page doesn’t contain a link tag with rel set to icon (the new
way of doing site icons.)
"""
if self.site_icon:
return
if not with_pyqt:
self.site_icon = None
return
ico_url = urllib.parse.urljoin(self.icon_url, "/favicon.ico")
ico_request = urllib.request.Request(ico_url)
if self.user_agent:
ico_request.add_header('User-agent', self.user_agent)
ico_response = urllib.request.urlopen(ico_request)
if 200 != ico_response.code:
self.site_icon = None
return
self.site_icon = QImage.fromData(ico_response.read())
max_size = QSize(self.max_icon_size, self.max_icon_size)
ico_size = self.site_icon.size()
if ico_size.width() > max_size.width() \
or ico_size.height() > max_size.height():
self.site_icon = self.site_icon.scaled(
max_size, Qt.KeepAspectRatio, Qt.SmoothTransformation)
示例5: minimumTabSizeHint
def minimumTabSizeHint(self, index):
"""Set the minimum tab size to indicator/icon/... text.
Args:
index: The index of the tab to get a size hint for.
Return:
A QSize.
"""
icon = self.tabIcon(index)
padding_count = 2
if icon.isNull():
icon_size = QSize(0, 0)
else:
extent = self.style().pixelMetric(QStyle.PM_TabBarIconSize, None,
self)
icon_size = icon.actualSize(QSize(extent, extent))
padding_count += 1
indicator_width = config.get('tabs', 'indicator-width')
if indicator_width != 0:
indicator_width += config.get('tabs', 'indicator-space')
padding_width = self.style().pixelMetric(PM_TabBarPadding, None, self)
height = self.fontMetrics().height()
width = (self.fontMetrics().width('\u2026') +
icon_size.width() + padding_count * padding_width +
indicator_width)
return QSize(width, height)
示例6: minimumTabSizeHint
def minimumTabSizeHint(self, index):
"""Set the minimum tab size to indicator/icon/... text.
Args:
index: The index of the tab to get a size hint for.
Return:
A QSize.
"""
icon = self.tabIcon(index)
padding = config.get('tabs', 'padding')
padding_h = padding.left + padding.right
padding_v = padding.top + padding.bottom
if icon.isNull():
icon_size = QSize(0, 0)
else:
extent = self.style().pixelMetric(QStyle.PM_TabBarIconSize, None,
self)
icon_size = icon.actualSize(QSize(extent, extent))
padding_h += self.style().pixelMetric(
PixelMetrics.icon_padding, None, self)
indicator_width = config.get('tabs', 'indicator-width')
height = self.fontMetrics().height() + padding_v
width = (self.fontMetrics().width('\u2026') + icon_size.width() +
padding_h + indicator_width)
return QSize(width, height)
示例7: __init__
def __init__(self, text, align=LEFT, userCode=0, parent=None, type=SIDEBAR):
super(TextButton, self).__init__(parent)
# Prevent a circular import.
from menumanager import MenuManager
self._menu_manager = MenuManager.instance()
self.menuString = text
self.buttonLabel = text
self.alignment = align
self.buttonType = type
self.userCode = userCode
self.scanAnim = None
self.bgOn = None
self.bgOff = None
self.bgHighlight = None
self.bgDisabled = None
self.state = TextButton.OFF
self.setAcceptHoverEvents(True)
self.setCursor(Qt.PointingHandCursor)
# Calculate the button size.
if type in (TextButton.SIDEBAR, TextButton.PANEL):
self.logicalSize = QSize(TextButton.BUTTON_WIDTH, TextButton.BUTTON_HEIGHT)
else:
self.logicalSize = QSize(int((TextButton.BUTTON_WIDTH / 2.0) - 5), int(TextButton.BUTTON_HEIGHT * 1.5))
self._prepared = False
示例8: minimumTabSizeHint
def minimumTabSizeHint(self, index):
"""Override minimumTabSizeHint because we want no hard minimum.
There are two problems with having a hard minimum tab size:
- When expanding is True, the window will expand without stopping
on some window managers.
- We don't want the main window to get bigger with many tabs. If
nothing else helps, we *do* want the tabs to get smaller instead
of enforcing a minimum window size.
Args:
index: The index of the tab to get a sizehint for.
Return:
A QSize.
"""
icon = self.tabIcon(index)
padding_count = 0
if not icon.isNull():
extent = self.style().pixelMetric(QStyle.PM_TabBarIconSize, None,
self)
icon_size = icon.actualSize(QSize(extent, extent))
padding_count += 1
else:
icon_size = QSize(0, 0)
padding_width = self.style().pixelMetric(PM_TabBarPadding, None, self)
height = self.fontMetrics().height()
width = (self.fontMetrics().size(0, '\u2026').width() +
icon_size.width() + padding_count * padding_width)
return QSize(width, height)
示例9: renderToTexture
def renderToTexture(self, levelOfDetail = 1.0):
# Determine the fbo size we will need.
size = (self.sceneRect().size() * levelOfDetail).toSize()
fboSize = nextPowerOfTwo(size)
if fboSize.isEmpty():
fboSize = QSize(16, 16)
# Create or re-create the fbo.
if self.fbo is None or self.fbo.size() != fboSize:
#del self.fbo
self.fbo = QGLFramebufferObject(fboSize, self.format)
if not self.fbo.isValid():
#del self.fbo
self.fbo = None
return 0
self.dirty = True
# Return the previous texture contents if the scene hasn't changed.
if self.fbo is not None and not self.dirty:
return self.fbo.texture()
# Render the scene into the fbo, scaling the QPainter's view
# transform up to the power-of-two fbo size.
painter = QPainter(self.fbo)
painter.setWindow(0, 0, size.width(), size.height())
painter.setViewport(0, 0, fboSize.width(), fboSize.height())
self.render(painter)
painter.end()
self.dirty = False
return self.fbo.texture()
示例10: minimumSize
def minimumSize(self):
# Return the largest "minimum size" of the items
size = QSize()
for item in self.items:
size = size.expandedTo(item.minimumSize())
margin, _, _, _ = self.getContentsMargins()
size += QSize(2 * margin, 2 * margin)
# self._logger.debug('size {} {}'.format(size.width(), size.height()))
return size
示例11: minimumSize
def minimumSize(self):
size = QSize()
for item in self.itemList:
size = size.expandedTo(item.minimumSize())
margin, _, _, _ = self.getContentsMargins()
size += QSize(2 * margin, 2 * margin)
return size
示例12: sizeHint
def sizeHint(self):
hint = QLabel.sizeHint(self)
if self.maximum_size_hint != None:
hint = QSize(max(hint.width(), self.maximum_size_hint.width()),
max(hint.height(), self.maximum_size_hint.height()))
self.maximum_size_hint = hint
return hint
示例13: _get_icon_rect
def _get_icon_rect(self, opt, text_rect):
"""Get a QRect for the icon to draw.
Args:
opt: QStyleOptionTab
text_rect: The QRect for the text.
Return:
A QRect.
"""
icon_size = opt.iconSize
if not icon_size.isValid():
icon_extent = self.pixelMetric(QStyle.PM_SmallIconSize)
icon_size = QSize(icon_extent, icon_extent)
icon_mode = (QIcon.Normal if opt.state & QStyle.State_Enabled
else QIcon.Disabled)
icon_state = (QIcon.On if opt.state & QStyle.State_Selected
else QIcon.Off)
tab_icon_size = opt.icon.actualSize(icon_size, icon_mode, icon_state)
tab_icon_size = QSize(min(tab_icon_size.width(), icon_size.width()),
min(tab_icon_size.height(), icon_size.height()))
icon_rect = QRect(text_rect.left(),
text_rect.center().y() - tab_icon_size.height() / 2,
tab_icon_size.width(), tab_icon_size.height())
icon_rect = self._style.visualRect(opt.direction, opt.rect, icon_rect)
qtutils.ensure_valid(icon_rect)
return icon_rect
示例14: __init__
def __init__(self, parent = None):
super().__init__(parent)
self.mMouseAnchorPoint = QPoint()
self.mOffset = QPoint()
self.mOldSize = QSize()
self.mDragging = False
self.mOffsetBounds = QRect()
self.mScale = 0.0
self.mNewSize = QSize()
self.mOrigOffset = QPoint()
self.setMinimumSize(20, 20)
self.setOldSize(QSize(1, 1))
示例15: FeatureTableWidgetHHeader
class FeatureTableWidgetHHeader(QTableWidgetItem):
sub_trans = str.maketrans('0123456789', '₀₁₂₃₄₅₆₇₈₉')
def __init__(self, column, sigma=None, window_size=3.5):
QTableWidgetItem.__init__(self)
# init
# ------------------------------------------------
self.column = column
self.sigma = sigma
self.window_size = window_size
self.pixmapSize = QSize(61, 61)
self.setNameAndBrush(self.sigma)
@property
def brushSize(self):
if self.sigma is None:
return 0
else:
return int(3.0 * self.sigma + 0.5) + 1
def setNameAndBrush(self, sigma, color=Qt.black):
self.sigma = sigma
self.setText(f'σ{self.column}'.translate(self.sub_trans))
if self.sigma is not None:
total_window = (1 + 2 * int(self.sigma * self.window_size + 0.5))
self.setToolTip(f'sigma = {sigma:.1f} pixels, window diameter = {total_window:.1f}')
font = QFont()
font.setPointSize(10)
# font.setBold(True)
self.setFont(font)
self.setForeground(color)
pixmap = QPixmap(self.pixmapSize)
pixmap.fill(Qt.transparent)
painter = QPainter()
painter.begin(pixmap)
painter.setRenderHint(QPainter.Antialiasing, True)
painter.setPen(color)
brush = QBrush(color)
painter.setBrush(brush)
painter.drawEllipse(QRect(old_div(self.pixmapSize.width(), 2) - old_div(self.brushSize, 2),
old_div(self.pixmapSize.height(), 2) - old_div(self.brushSize, 2),
self.brushSize, self.brushSize))
painter.end()
self.setIcon(QIcon(pixmap))
self.setTextAlignment(Qt.AlignVCenter)
def setIconAndTextColor(self, color):
self.setNameAndBrush(self.sigma, color)