QGraphicsItem 选中和焦点问题

来源:互联网 发布:java定时任务管理系统 编辑:程序博客网 时间:2024/06/05 18:56
void ComponetCommonSlot::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    Q_UNUSED(event)
    setCursor(QCursor(Qt::ClosedHandCursor));
    setSelected(true);
}

void ComponetCommonSlot::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    Q_UNUSED(event)
    setCursor(QCursor(Qt::OpenHandCursor));
}

void ComponetCommonSlot::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
    Q_UNUSED(event)
    setCursor(QCursor(Qt::OpenHandCursor));
    setSelected(false);
}
++++++++++++++

QGraphicsItem.GraphicsItemFlag

This enum describes different flags that you can set on an item to toggle different features in the item's behavior.

All flags are disabled by default.

ConstantValueDescriptionQGraphicsItem.ItemIsMovable0x1The item supports interactive movement using the mouse. By clicking on the item and then dragging, the item will move together with the mouse cursor. If the item has children, all children are also moved. If the item is part of a selection, all selected items are also moved. This feature is provided as a convenience through the base implementation of QGraphicsItem's mouse event handlers.QGraphicsItem.ItemIsSelectable0x2The item supports selection. Enabling this feature will enable setSelected() to toggle selection for the item. It will also let the item be selected automatically as a result of calling QGraphicsScene.setSelectionArea(), by clicking on an item, or by using rubber band selection in QGraphicsView.QGraphicsItem.ItemIsFocusable0x4The item supports keyboard input focus (i.e., it is an input item). Enabling this flag will allow the item to accept focus, which again allows the delivery of key events to QGraphicsItem.keyPressEvent() and QGraphicsItem.keyReleaseEvent().QGraphicsItem.ItemClipsToShape0x8The item clips to its own shape. The item cannot draw or receive mouse, tablet, drag and drop or hover events outside its shape. It is disabled by default. This behavior is enforced by QGraphicsView.drawItems() or QGraphicsScene.drawItems(). This flag was introduced in Qt 4.3.QGraphicsItem.ItemClipsChildrenToShape0x10The item clips the painting of all its descendants to its own shape. Items that are either direct or indirect children of this item cannot draw outside this item's shape. By default, this flag is disabled; children can draw anywhere. This behavior is enforced by QGraphicsView.drawItems() or QGraphicsScene.drawItems(). This flag was introduced in Qt 4.3.QGraphicsItem.ItemIgnoresTransformations0x20The item ignores inherited transformations (i.e., its position is still anchored to its parent, but the parent or view rotation, zoom or shear transformations are ignored). This flag is useful for keeping text label items horizontal and unscaled, so they will still be readable if the view is transformed. When set, the item's view geometry and scene geometry will be maintained separately. You must calldeviceTransform() to map coordinates and detect collisions in the view. By default, this flag is disabled. This flag was introduced in Qt 4.3. Note: With this flag set you can still scale the item itself, and that scale transformation will influence the item's children.QGraphicsItem.ItemIgnoresParentOpacity0x40The item ignores its parent's opacity. The item's effective opacity is the same as its own; it does not combine with the parent's opacity. This flags allows your item to keep its absolute opacity even if the parent is semitransparent. This flag was introduced in Qt 4.5.QGraphicsItem.ItemDoesntPropagateOpacityToChildren0x80The item doesn't propagate its opacity to its children. This flag allows you to create a semitransparent item that does not affect the opacity of its children. This flag was introduced in Qt 4.5.QGraphicsItem.ItemStacksBehindParent0x100The item is stacked behind its parent. By default, child items are stacked on top of the parent item. But setting this flag, the child will be stacked behind it. This flag is useful for drop shadow effects and for decoration objects that follow the parent item's geometry without drawing on top of it. This flag was introduced in Qt 4.5.QGraphicsItem.ItemUsesExtendedStyleOption0x200The item makes use of either exposedRect or matrix(obsolete) inQStyleOptionGraphicsItem. By default, the exposedRect is initialized to the item'sboundingRect() and the matrix(obsolete) is untransformed. You can enable this flag for the style options to be set up with more fine-grained values. Note thatQStyleOptionGraphicsItem.levelOfDetail(obsolete) is unaffected by this flag and always initialized to 1. Use QStyleOptionGraphicsItem.levelOfDetailFromTransform() if you need a higher value. This flag was introduced in Qt 4.6.QGraphicsItem.ItemHasNoContents0x400The item does not paint anything (i.e., calling paint() on the item has no effect). You should set this flag on items that do not need to be painted to ensure that Graphics View avoids unnecessary painting preparations. This flag was introduced in Qt 4.6.QGraphicsItem.ItemSendsGeometryChanges0x800The item enables itemChange() notifications for ItemPositionChange,ItemPositionHasChanged, ItemMatrixChange, ItemTransformChange,ItemTransformHasChanged, ItemRotationChange, ItemRotationHasChanged,ItemScaleChange, ItemScaleHasChanged, ItemTransformOriginPointChange, andItemTransformOriginPointHasChanged. For performance reasons, these notifications are disabled by default. You must enable this flag to receive notifications for position and transform changes. This flag was introduced in Qt 4.6.QGraphicsItem.ItemAcceptsInputMethod0x1000The item supports input methods typically used for Asian languages. This flag was introduced in Qt 4.6.QGraphicsItem.ItemNegativeZStacksBehindParent0x2000The item automatically stacks behind it's parent if it's z-value is negative. This flag enables setZValue() to toggle ItemStacksBehindParent. This flag was introduced in Qt 4.6.QGraphicsItem.ItemIsPanel0x4000The item is a panel. A panel provides activation and contained focus handling. Only one panel can be active at a time (see QGraphicsItem.isActive()). When no panel is active, QGraphicsScene activates all non-panel items. Window items (i.e.,QGraphicsItem.isWindow() returns true) are panels. This flag was introduced in Qt 4.6.QGraphicsItem.ItemSendsScenePositionChanges0x10000The item enables itemChange() notifications for ItemScenePositionHasChanged. For performance reasons, these notifications are disabled by default. You must enable this flag to receive notifications for scene position changes. This flag was introduced in Qt 4.6.
原创粉丝点击