本文整理汇总了Python中AnyQt.QtCore.QRectF.normalized方法的典型用法代码示例。如果您正苦于以下问题:Python QRectF.normalized方法的具体用法?Python QRectF.normalized怎么用?Python QRectF.normalized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtCore.QRectF
的用法示例。
在下文中一共展示了QRectF.normalized方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __activeControlMoved
# 需要导入模块: from AnyQt.QtCore import QRectF [as 别名]
# 或者: from AnyQt.QtCore.QRectF import normalized [as 别名]
def __activeControlMoved(self, pos):
# The active control point has moved, update the control
# rectangle
control = self.__activeControl
pos = control.pos()
rect = QRectF(self.__rect)
margins = self.__margins
# TODO: keyboard modifiers and constraints.
anchor = control.anchor()
if anchor & ControlPoint.Top:
rect.setTop(pos.y() + margins.top())
elif anchor & ControlPoint.Bottom:
rect.setBottom(pos.y() - margins.bottom())
if anchor & ControlPoint.Left:
rect.setLeft(pos.x() + margins.left())
elif anchor & ControlPoint.Right:
rect.setRight(pos.x() - margins.right())
changed = self.__rect != rect
self.blockSignals(True)
self.setRect(rect)
self.blockSignals(False)
if changed:
self.rectEdited.emit(rect.normalized())
示例2: RectangleSelectionAction
# 需要导入模块: from AnyQt.QtCore import QRectF [as 别名]
# 或者: from AnyQt.QtCore.QRectF import normalized [as 别名]
class RectangleSelectionAction(UserInteraction):
"""
Select items in the scene using a Rectangle selection
"""
def __init__(self, document, *args, **kwargs):
UserInteraction.__init__(self, document, *args, **kwargs)
# The initial selection at drag start
self.initial_selection = None
# Selection when last updated in a mouseMoveEvent
self.last_selection = None
# A selection rect (`QRectF`)
self.selection_rect = None
# Keyboard modifiers
self.modifiers = 0
def mousePressEvent(self, event):
pos = event.scenePos()
any_item = self.scene.item_at(pos)
if not any_item and event.button() & Qt.LeftButton:
self.modifiers = event.modifiers()
self.selection_rect = QRectF(pos, QSizeF(0, 0))
self.rect_item = QGraphicsRectItem(
self.selection_rect.normalized()
)
self.rect_item.setPen(
QPen(QBrush(QColor(51, 153, 255, 192)),
0.4, Qt.SolidLine, Qt.RoundCap)
)
self.rect_item.setBrush(
QBrush(QColor(168, 202, 236, 192))
)
self.rect_item.setZValue(-100)
# Clear the focus if necessary.
if not self.scene.stickyFocus():
self.scene.clearFocus()
if not self.modifiers & Qt.ControlModifier:
self.scene.clearSelection()
event.accept()
return True
else:
self.cancel(self.ErrorReason)
return False
def mouseMoveEvent(self, event):
if not self.rect_item.scene():
# Add the rect item to the scene when the mouse moves.
self.scene.addItem(self.rect_item)
self.update_selection(event)
return True
def mouseReleaseEvent(self, event):
if event.button() == Qt.LeftButton:
if self.initial_selection is None:
# A single click.
self.scene.clearSelection()
else:
self.update_selection(event)
self.end()
return True
def update_selection(self, event):
"""
Update the selection rectangle from a QGraphicsSceneMouseEvent
`event` instance.
"""
if self.initial_selection is None:
self.initial_selection = set(self.scene.selectedItems())
self.last_selection = self.initial_selection
pos = event.scenePos()
self.selection_rect = QRectF(self.selection_rect.topLeft(), pos)
# Make sure the rect_item does not cause the scene rect to grow.
rect = self._bound_selection_rect(self.selection_rect.normalized())
# Need that 0.5 constant otherwise the sceneRect will still
# grow (anti-aliasing correction by QGraphicsScene?)
pw = self.rect_item.pen().width() + 0.5
self.rect_item.setRect(rect.adjusted(pw, pw, -pw, -pw))
selected = self.scene.items(self.selection_rect.normalized(),
Qt.IntersectsItemShape,
Qt.AscendingOrder)
selected = set([item for item in selected if \
item.flags() & Qt.ItemIsSelectable])
if self.modifiers & Qt.ControlModifier:
for item in selected | self.last_selection | \
self.initial_selection:
item.setSelected(
(item in selected) ^ (item in self.initial_selection)
#.........这里部分代码省略.........
示例3: ControlPointRect
# 需要导入模块: from AnyQt.QtCore import QRectF [as 别名]
# 或者: from AnyQt.QtCore.QRectF import normalized [as 别名]
class ControlPointRect(QGraphicsObject):
Free = 0
KeepAspectRatio = 1
KeepCenter = 2
rectChanged = Signal(QRectF)
rectEdited = Signal(QRectF)
def __init__(self, parent=None, rect=None, constraints=0, **kwargs):
QGraphicsObject.__init__(self, parent, **kwargs)
self.setFlag(QGraphicsItem.ItemHasNoContents)
self.setFlag(QGraphicsItem.ItemIsFocusable)
self.__rect = rect if rect is not None else QRectF()
self.__margins = QMargins()
points = \
[ControlPoint(self, ControlPoint.Left),
ControlPoint(self, ControlPoint.Top),
ControlPoint(self, ControlPoint.TopLeft),
ControlPoint(self, ControlPoint.Right),
ControlPoint(self, ControlPoint.TopRight),
ControlPoint(self, ControlPoint.Bottom),
ControlPoint(self, ControlPoint.BottomLeft),
ControlPoint(self, ControlPoint.BottomRight)
]
assert(points == sorted(points, key=lambda p: p.anchor()))
self.__points = dict((p.anchor(), p) for p in points)
if self.scene():
self.__installFilter()
for p in points:
p.setFlag(QGraphicsItem.ItemIsFocusable)
p.setFocusProxy(self)
self.controlPoint(ControlPoint.Top).setConstraint(Qt.Vertical)
self.controlPoint(ControlPoint.Bottom).setConstraint(Qt.Vertical)
self.controlPoint(ControlPoint.Left).setConstraint(Qt.Horizontal)
self.controlPoint(ControlPoint.Right).setConstraint(Qt.Horizontal)
self.__constraints = constraints
self.__activeControl = None
self.__pointsLayout()
def controlPoint(self, anchor):
"""
Return the anchor point (:class:`ControlPoint`) at anchor position
or `None` if an anchor point is not set.
"""
return self.__points.get(anchor)
def setRect(self, rect):
"""
Set the control point rectangle (:class:`QRectF`)
"""
if self.__rect != rect:
self.__rect = QRectF(rect)
self.__pointsLayout()
self.prepareGeometryChange()
self.rectChanged.emit(rect.normalized())
def rect(self):
"""
Return the control point rectangle.
"""
# Return the rect normalized. During the control point move the
# rect can change to an invalid size, but the layout must still
# know to which point does an unnormalized rect side belong,
# so __rect is left unnormalized.
# NOTE: This means all signal emits (rectChanged/Edited) must
# also emit normalized rects
return self.__rect.normalized()
rect_ = Property(QRectF, fget=rect, fset=setRect, user=True)
def setControlMargins(self, *margins):
"""Set the controls points on the margins around `rect`
"""
if len(margins) > 1:
margins = QMargins(*margins)
else:
margins = margins[0]
if isinstance(margins, int):
margins = QMargins(margins, margins, margins, margins)
if self.__margins != margins:
self.__margins = margins
self.__pointsLayout()
def controlMargins(self):
return self.__margins
def setConstraints(self, constraints):
raise NotImplementedError
def isControlActive(self):
"""Return the state of the control. True if the control is
#.........这里部分代码省略.........