本文整理汇总了Python中AnyQt.QtCore.QRect类的典型用法代码示例。如果您正苦于以下问题:Python QRect类的具体用法?Python QRect怎么用?Python QRect使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QRect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: decorate_welcome_icon
def decorate_welcome_icon(icon, background_color):
"""Return a `QIcon` with a circle shaped background.
"""
welcome_icon = QIcon()
sizes = [32, 48, 64, 80, 128, 256]
background_color = NAMED_COLORS.get(background_color, background_color)
background_color = QColor(background_color)
grad = radial_gradient(background_color)
for size in sizes:
icon_size = QSize(5 * size / 8, 5 * size / 8)
icon_rect = QRect(QPoint(0, 0), icon_size)
pixmap = QPixmap(size, size)
pixmap.fill(Qt.transparent)
p = QPainter(pixmap)
p.setRenderHint(QPainter.Antialiasing, True)
p.setBrush(QBrush(grad))
p.setPen(Qt.NoPen)
ellipse_rect = QRect(0, 0, size, size)
p.drawEllipse(ellipse_rect)
icon_rect.moveCenter(ellipse_rect.center())
icon.paint(p, icon_rect, Qt.AlignCenter, )
p.end()
welcome_icon.addPixmap(pixmap)
return welcome_icon
示例2: __updateGeometry
def __updateGeometry(self):
"""
Update the shadow geometry to fit the widget's changed
geometry.
"""
widget = self.__widget
parent = self.__widgetParent
radius = self.radius_
pos = widget.pos()
if parent != widget.parentWidget():
pos = widget.parentWidget().mapTo(parent, pos)
geom = QRect(pos, widget.size())
geom.adjust(-radius, -radius, radius, radius)
if geom != self.geometry():
self.setGeometry(geom)
# Set the widget mask (punch a hole through to the `widget` instance.
rect = self.rect()
mask = QRegion(rect)
transparent = QRegion(rect.adjusted(radius, radius, -radius, -radius))
mask = mask.subtracted(transparent)
self.setMask(mask)
示例3: __setControlAreaVisible
def __setControlAreaVisible(self, visible):
# type: (bool) -> None
if self.__splitter is None or self.__splitter.count() < 2:
return
self.controlAreaVisible = visible
splitter = self.__splitter # type: QSplitter
w = splitter.widget(0)
# Set minimum width to 1 (overrides minimumSizeHint) when control area
# is not visible to allow the main area to shrink further. Reset the
# minimum width with a 0 if control area is visible.
w.setMinimumWidth(int(not visible))
sizes = splitter.sizes()
current_size = sizes[0]
if bool(current_size) == visible:
return
current_width = w.width()
geom = self.geometry()
frame = self.frameGeometry()
framemargins = QMargins(
frame.left() - geom.left(),
frame.top() - geom.top(),
frame.right() - geom.right(),
frame.bottom() - geom.bottom()
)
splitter.setSizes([int(visible), QWIDGETSIZE_MAX])
if not self.isWindow() or \
self.windowState() not in [Qt.WindowNoState, Qt.WindowActive]:
# not a window or not in state where we can move move/resize
return
# force immediate resize recalculation
splitter.refresh()
self.layout().invalidate()
self.layout().activate()
if visible:
# move left and expand by the exposing widget's width
diffx = -w.width()
diffw = w.width()
else:
# move right and shrink by the collapsing width
diffx = current_width
diffw = -current_width
newgeom = QRect(
geom.x() + diffx, geom.y(), geom.width() + diffw, geom.height()
)
# bound/move by available geometry
bounds = QApplication.desktop().availableGeometry(self)
bounds = bounds.adjusted(
framemargins.left(), framemargins.top(),
-framemargins.right(), -framemargins.bottom()
)
newsize = newgeom.size().boundedTo(bounds.size())
newgeom = QRect(newgeom.topLeft(), newsize)
newgeom.moveLeft(max(newgeom.left(), bounds.left()))
newgeom.moveRight(min(newgeom.right(), bounds.right()))
self.setGeometry(newgeom)
示例4: setGeometry
def setGeometry(self, rect):
QStackedLayout.setGeometry(self, rect)
for i in range(self.count()):
w = self.widget(i)
hint = w.sizeHint()
geom = QRect(rect)
size = clipMinMax(rect.size(), w.minimumSize(), w.maximumSize())
size = fixSizePolicy(size, hint, w.sizePolicy())
geom.setSize(size)
if geom != w.geometry():
w.setGeometry(geom)
示例5: fitRect
def fitRect(rect, targetrect):
size = rect.size().boundedTo(targetgeom.size())
newrect = QRect(rect.topLeft(), size)
dx, dy = 0, 0
if newrect.left() < targetrect.left():
dx = targetrect.left() - newrect.left()
if newrect.top() < targetrect.top():
dy = targetrect.top() - newrect.top()
if newrect.right() > targetrect.right():
dx = targetrect.right() - newrect.right()
if newrect.bottom() > targetrect.bottom():
dy = targetrect.bottom() - newrect.bottom()
return newrect.translated(dx, dy)
示例6: __updateWindowGeometry
def __updateWindowGeometry(self):
if not self.isWindow() or self.__hasExplicitSize:
return
def framemargins(widget):
frame, geom = widget.frameGeometry(), widget.geometry()
return QMargins(geom.left() - frame.left(),
geom.top() - frame.top(),
geom.right() - frame.right(),
geom.bottom() - frame.bottom())
def fitRect(rect, targetrect):
size = rect.size().boundedTo(targetgeom.size())
newrect = QRect(rect.topLeft(), size)
dx, dy = 0, 0
if newrect.left() < targetrect.left():
dx = targetrect.left() - newrect.left()
if newrect.top() < targetrect.top():
dy = targetrect.top() - newrect.top()
if newrect.right() > targetrect.right():
dx = targetrect.right() - newrect.right()
if newrect.bottom() > targetrect.bottom():
dy = targetrect.bottom() - newrect.bottom()
return newrect.translated(dx, dy)
margins = framemargins(self)
minsize = QSize(120, 120)
pixsize = self.__pixmap.size()
available = QApplication.desktop().availableGeometry(self)
available = available.adjusted(margins.left(), margins.top(),
-margins.right(), -margins.bottom())
# extra adjustment so the preview does not cover the whole desktop
available = available.adjusted(10, 10, -10, -10)
targetsize = pixsize.boundedTo(available.size()).expandedTo(minsize)
pixsize.scale(targetsize, Qt.KeepAspectRatio)
if not self.testAttribute(Qt.WA_WState_Created) or \
self.testAttribute(Qt.WA_WState_Hidden):
center = available.center()
else:
center = self.geometry().center()
targetgeom = QRect(QPoint(0, 0), pixsize)
targetgeom.moveCenter(center)
if not available.contains(targetgeom):
targetgeom = fitRect(targetgeom, available)
self.__inUpdateWindowGeometry = True
self.setGeometry(targetgeom)
self.__inUpdateWindowGeometry = False
示例7: __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)
示例8: testArrowContact
def testArrowContact(self, indices, x, y):
if type(indices) != list: indices = [indices]
for index in indices:
if index >= len(self.attributes) or index < 0:
continue
int_x = self.transform(xBottom, index)
bottom = self.transform(yLeft,
self.selection_conditions.get(self.attributes[index], [0, 1])[0])
bottom_rect = QRect(int_x - self.bottom_pixmap.width() / 2, bottom, self.bottom_pixmap.width(),
self.bottom_pixmap.height())
if bottom_rect.contains(QPoint(x, y)):
return 1, (index, 0)
top = self.transform(yLeft,
self.selection_conditions.get(self.attributes[index], [0, 1])[1])
top_rect = QRect(int_x - self.top_pixmap.width() / 2, top - self.top_pixmap.height(),
self.top_pixmap.width(),
self.top_pixmap.height())
if top_rect.contains(QPoint(x, y)):
return 1, (index, 1)
return 0, (0, 0)
示例9: setGeometry
def setGeometry(self, rect):
if not isinstance(rect, QRect):
raise TypeError("QRect required")
if rect == self.__rect:
return
self.__rect = QRect(rect)
super().setGeometry(rect)
for i in range(self.count()):
w = self.widget(i)
hint = w.sizeHint()
geom = QRect(rect)
size = clipMinMax(rect.size(), w.minimumSize(), w.maximumSize())
size = fixSizePolicy(size, hint, w.sizePolicy())
geom.setSize(size)
if geom != w.geometry():
w.setGeometry(geom)
示例10: __autoScrollAdvance
def __autoScrollAdvance(self):
"""Advance the auto scroll
"""
pos = QCursor.pos()
pos = self.mapFromGlobal(pos)
margin = self.__autoScrollMargin
vvalue = self.verticalScrollBar().value()
hvalue = self.horizontalScrollBar().value()
vrect = QRect(0, 0, self.width(), self.height())
# What should be the speed
advance = 10
# We only do auto scroll if the mouse is inside the view.
if vrect.contains(pos):
if pos.x() < vrect.left() + margin:
self.horizontalScrollBar().setValue(hvalue - advance)
if pos.y() < vrect.top() + margin:
self.verticalScrollBar().setValue(vvalue - advance)
if pos.x() > vrect.right() - margin:
self.horizontalScrollBar().setValue(hvalue + advance)
if pos.y() > vrect.bottom() - margin:
self.verticalScrollBar().setValue(vvalue + advance)
if self.verticalScrollBar().value() == vvalue and \
self.horizontalScrollBar().value() == hvalue:
self.__stopAutoScroll()
else:
self.__stopAutoScroll()
log.debug("Auto scroll advance")
示例11: drawBackground
def drawBackground(self, painter, rect):
super().drawBackground(painter, rect)
if not self.__backgroundIcon.isNull():
painter.setClipRect(rect)
vrect = QRect(QPoint(0, 0), self.viewport().size())
vrect = self.mapToScene(vrect).boundingRect()
pm = self.__backgroundIcon.pixmap(
vrect.size().toSize().boundedTo(QSize(200, 200))
)
pmrect = QRect(QPoint(0, 0), pm.size())
pmrect.moveCenter(vrect.center().toPoint())
if rect.toRect().intersects(pmrect):
painter.drawPixmap(pmrect, pm)
示例12: popup_position_from_source
def popup_position_from_source(popup, source, orientation=Qt.Vertical):
popup.ensurePolished()
source.ensurePolished()
if popup.testAttribute(Qt.WA_Resized):
size = popup.size()
else:
size = popup.sizeHint()
desktop = QApplication.desktop()
screen_geom = desktop.availableGeometry(source)
source_rect = QRect(source.mapToGlobal(QPoint(0, 0)), source.size())
if orientation == Qt.Vertical:
if source_rect.right() + size.width() < screen_geom.right():
x = source_rect.right()
else:
x = source_rect.left() - size.width()
# bottom overflow
dy = source_rect.top() + size.height() - screen_geom.bottom()
if dy < 0:
y = source_rect.top()
else:
y = source_rect.top() - dy
else:
# right overflow
dx = source_rect.left() + size.width() - screen_geom.right()
if dx < 0:
x = source_rect.left()
else:
x = source_rect.left() - dx
if source_rect.bottom() + size.height() < screen_geom.bottom():
y = source_rect.bottom()
else:
y = source_rect.top() - size.height()
return QPoint(x, y)
示例13: widget_popup_geometry
def widget_popup_geometry(pos, widget):
widget.ensurePolished()
if widget.testAttribute(Qt.WA_Resized):
size = widget.size()
else:
size = widget.sizeHint()
desktop = QApplication.desktop()
screen_geom = desktop.availableGeometry(pos)
# Adjust the size to fit inside the screen.
if size.height() > screen_geom.height():
size.setHeight(screen_geom.height())
if size.width() > screen_geom.width():
size.setWidth(screen_geom.width())
geom = QRect(pos, size)
if geom.top() < screen_geom.top():
geom.setTop(screen_geom.top())
if geom.left() < screen_geom.left():
geom.setLeft(screen_geom.left())
bottom_margin = screen_geom.bottom() - geom.bottom()
right_margin = screen_geom.right() - geom.right()
if bottom_margin < 0:
# Falls over the bottom of the screen, move it up.
geom.translate(0, bottom_margin)
# TODO: right to left locale
if right_margin < 0:
# Falls over the right screen edge, move the menu to the
# other side of pos.
geom.translate(-size.width(), 0)
return geom
示例14: paint
def paint(self, painter, option, index):
rect = QRect(option.rect)
is_selected = index.data(VariableSelectionModel.IsSelected)
if option.state & QStyle.State_MouseOver:
txt = [" Add ", " Remove "][is_selected]
txtw = painter.fontMetrics().width(txt)
painter.save()
painter.setPen(Qt.NoPen)
painter.setBrush(QColor("#ccc"))
brect = QRect(rect.x() + rect.width() - 8 - txtw, rect.y(),
txtw, rect.height())
painter.drawRoundedRect(brect, 4, 4)
painter.restore()
painter.drawText(brect, Qt.AlignCenter, txt)
painter.save()
double_pen = painter.pen()
double_pen.setWidth(2 * double_pen.width())
if is_selected:
next = index.sibling(index.row() + 1, index.column())
if not next.isValid():
painter.setPen(double_pen)
painter.drawLine(rect.bottomLeft(), rect.bottomRight())
elif not next.data(VariableSelectionModel.IsSelected):
painter.drawLine(rect.bottomLeft(), rect.bottomRight())
elif not index.row():
down = QPoint(0, painter.pen().width())
painter.setPen(double_pen)
painter.drawLine(rect.topLeft() + down, rect.topRight() + down)
else:
prev = index.sibling(index.row() - 1, index.column())
if prev.data(VariableSelectionModel.IsSelected):
painter.drawLine(rect.topLeft(), rect.topRight())
painter.restore()
super().paint(painter, option, index)
示例15: popup
def popup(self, pos=None, searchText=""):
"""
Popup the menu at `pos` (in screen coordinates). 'Search' text field
is initialized with `searchText` if provided.
"""
if pos is None:
pos = QPoint()
self.__clearCurrentItems()
self.__search.setText(searchText)
patt = QRegExp("(^|\W)"+searchText)
patt.setCaseSensitivity(False)
self.__suggestPage.setFilterRegExp(patt)
UsageStatistics.set_last_search_query(searchText)
self.ensurePolished()
if self.testAttribute(Qt.WA_Resized) and self.sizeGripEnabled():
size = self.size()
else:
size = self.sizeHint()
desktop = QApplication.desktop()
screen_geom = desktop.availableGeometry(pos)
# Adjust the size to fit inside the screen.
if size.height() > screen_geom.height():
size.setHeight(screen_geom.height())
if size.width() > screen_geom.width():
size.setWidth(screen_geom.width())
geom = QRect(pos, size)
if geom.top() < screen_geom.top():
geom.setTop(screen_geom.top())
if geom.left() < screen_geom.left():
geom.setLeft(screen_geom.left())
bottom_margin = screen_geom.bottom() - geom.bottom()
right_margin = screen_geom.right() - geom.right()
if bottom_margin < 0:
# Falls over the bottom of the screen, move it up.
geom.translate(0, bottom_margin)
# TODO: right to left locale
if right_margin < 0:
# Falls over the right screen edge, move the menu to the
# other side of pos.
geom.translate(-size.width(), 0)
self.setGeometry(geom)
self.show()
self.setFocusProxy(self.__search)