|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.gui.QGraphicsPixmapItem
public class QGraphicsPixmapItem
The QGraphicsPixmapItem class provides a pixmap item that you can add to a QGraphicsScene
. To set the item's pixmap, pass a QPixmap
to QGraphicsPixmapItem's constructor, or call the setPixmap()
function. The pixmap()
function returns the current pixmap.
QGraphicsPixmapItem uses pixmap's optional alpha mask to provide a reasonable implementation of boundingRect()
, shape()
, and contains()
.
offset()
. You can change the drawing offset by calling setOffset()
. You can set the pixmap's transformation mode by calling setTransformationMode()
. By default, Qt::FastTransformation
is used, which provides fast, non-smooth scaling. Qt::SmoothTransformation
enables QPainter::SmoothPixmapTransform
on the painter, and the quality depends on the platform and viewport. The result is usually not as good as calling QPixmap::scale() directly. Call transformationMode()
to get the current transformation mode for the item.
QGraphicsPathItem
, QGraphicsRectItem
, QGraphicsEllipseItem
, QGraphicsTextItem
, QGraphicsPolygonItem
, QGraphicsLineItem
, and The Graphics View Framework.
Nested Class Summary | |
---|---|
static class |
QGraphicsPixmapItem.enum_1
|
static class |
QGraphicsPixmapItem.ShapeMode
This enum describes how QGraphicsPixmapItem calculates its shape and opaque area. |
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal |
Field Summary |
---|
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
currentSender |
Constructor Summary | |
---|---|
QGraphicsPixmapItem()
Constructs a QGraphicsPixmapItem. |
|
QGraphicsPixmapItem(QGraphicsItemInterface parent)
Constructs a QGraphicsPixmapItem. |
|
QGraphicsPixmapItem(QGraphicsItemInterface parent,
QGraphicsScene scene)
Constructs a QGraphicsPixmapItem. |
|
QGraphicsPixmapItem(QPixmap pixmap)
Creates a new QGraphicsPixmapItem from the given pixmap. |
|
QGraphicsPixmapItem(QPixmap pixmap,
QGraphicsItemInterface parent)
Creates a new QGraphicsPixmapItem from pixmap and with the specified parent. |
|
QGraphicsPixmapItem(QPixmap pixmap,
QGraphicsItemInterface parent,
QGraphicsScene scene)
Creates a new QGraphicsPixmapItem from the given pixmap and with the specified parent. |
Method Summary | |
---|---|
boolean |
acceptDrops()
Returns true if this item can accept drag and drop events; otherwise, returns false. |
Qt.MouseButtons |
acceptedMouseButtons()
Returns the mouse buttons that this item accepts mouse events for. |
boolean |
acceptHoverEvents()
Returns true if an item accepts hover events ( QGraphicsSceneHoverEvent ); otherwise, returns false. |
boolean |
acceptsHoverEvents()
Call acceptHoverEvents() instead. |
void |
advance(int phase)
This virtual function is called twice for all items by the QGraphicsScene::advance() slot. |
QRectF |
boundingRect()
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be restricted to inside an item's bounding rect. |
QRegion |
boundingRegion(QTransform itemToDeviceTransform)
Returns the bounding region for this item. |
double |
boundingRegionGranularity()
Returns the item's bounding region granularity; a value between and including 0 and 1. |
QGraphicsItem.CacheMode |
cacheMode()
Returns the cache mode for this item. |
java.util.List |
childItems()
Returns a list of this item's children. |
QRectF |
childrenBoundingRect()
Returns the bounding rect of this item's descendants (i. |
void |
clearFocus()
Takes keyboard input focus from the item. |
QPainterPath |
clipPath()
Returns this item's clip path, or an empty QPainterPath if this item is not clipped. |
boolean |
collidesWithItem(QGraphicsItemInterface other,
Qt.ItemSelectionMode mode)
Returns true if this item collides with other; otherwise returns false. |
boolean |
collidesWithPath(QPainterPath path,
Qt.ItemSelectionMode mode)
Returns true if this item collides with path. |
java.util.List |
collidingItems(Qt.ItemSelectionMode mode)
Returns a list of all items that collide with this item. |
QGraphicsItemInterface |
commonAncestorItem(QGraphicsItemInterface other)
Returns the closest common ancestor item of this item and other, or 0 if either other is 0, or there is no common ancestor. |
boolean |
contains(QPointF point)
Returns true if this item contains point, which is in local coordinates; otherwise, false is returned. |
void |
contextMenuEvent(QGraphicsSceneContextMenuEvent event)
This event handler can be reimplemented in a subclass to process context menu events. |
QCursor |
cursor()
Returns the current cursor shape for the item. |
java.lang.Object |
data(int key)
Returns this item's custom data for the key key as a QVariant . |
QTransform |
deviceTransform(QTransform viewportTransform)
Returns this item's device transformation matrix, using viewportTransform to map from scene to device coordinates. |
void |
dragEnterEvent(QGraphicsSceneDragDropEvent event)
This event handler, for event event, can be reimplemented to receive drag enter events for this item. |
void |
dragLeaveEvent(QGraphicsSceneDragDropEvent event)
This event handler, for event event, can be reimplemented to receive drag leave events for this item. |
void |
dragMoveEvent(QGraphicsSceneDragDropEvent event)
This event handler, for event event, can be reimplemented to receive drag move events for this item. |
void |
dropEvent(QGraphicsSceneDragDropEvent event)
This event handler, for event event, can be reimplemented to receive drop events for this item. |
double |
effectiveOpacity()
Returns this item's effective opacity, which is between 0. |
void |
ensureVisible(double x,
double y,
double w,
double h,
int xmargin,
int ymargin)
This convenience function is equivalent to calling ensureVisible( QRectF (x, y, w, h), xmargin, ymargin): |
void |
ensureVisible(QRectF rect,
int xmargin,
int ymargin)
If this item is part of a scene that is viewed by a QGraphicsView , this convenience function will attempt to scroll the view to ensure that rect is visible inside the view's viewport. |
QGraphicsItem.GraphicsItemFlags |
flags()
Returns this item's flags. |
void |
focusInEvent(QFocusEvent event)
This event handler, for event event, can be reimplemented to receive focus in events for this item. |
void |
focusOutEvent(QFocusEvent event)
This event handler, for event event, can be reimplemented to receive focus out events for this item. |
void |
grabKeyboard()
Grabs the keyboard input. |
void |
grabMouse()
Grabs the mouse input. |
QGraphicsItemGroup |
group()
Returns a pointer to this item's item group, or 0 if this item is not member of a group. |
boolean |
handlesChildEvents()
Returns true if this item handles child events (i. |
boolean |
hasCursor()
Returns true if this item has a cursor set; otherwise, false is returned. |
boolean |
hasFocus()
Returns true if this item has keyboard input focus; otherwise, returns false. |
void |
hide()
Hides the item. |
void |
hoverEnterEvent(QGraphicsSceneHoverEvent event)
This event handler, for event event, can be reimplemented to receive hover enter events for this item. |
void |
hoverLeaveEvent(QGraphicsSceneHoverEvent event)
This event handler, for event event, can be reimplemented to receive hover leave events for this item. |
void |
hoverMoveEvent(QGraphicsSceneHoverEvent event)
This event handler, for event event, can be reimplemented to receive hover move events for this item. |
void |
inputMethodEvent(QInputMethodEvent event)
This event handler, for event event, can be reimplemented to receive input method events for this item. |
java.lang.Object |
inputMethodQuery(Qt.InputMethodQuery query)
This method is only relevant for input items. |
void |
installSceneEventFilter(QGraphicsItemInterface filterItem)
Installs an event filter for this item on filterItem, causing all events for this item to first pass through filterItem's sceneEventFilter() function. |
boolean |
isAncestorOf(QGraphicsItemInterface child)
Returns true if this item is an ancestor of child (i. |
boolean |
isClipped()
Returns true if this item is clipped. |
boolean |
isEnabled()
Returns true if the item is enabled; otherwise, false is returned. |
boolean |
isObscured()
Returns true if this item's bounding rect is completely obscured by the opaque shape of any of colliding items above it (i. |
boolean |
isObscured(double x,
double y,
double w,
double h)
This convenience function is equivalent to calling isObscured( QRectF (x, y, w, h)). |
boolean |
isObscured(QRectF rect)
This is an overloaded member function, provided for convenience. |
boolean |
isObscuredBy(QGraphicsItemInterface item)
Returns true if this item's bounding rect is completely obscured by the opaque shape of item. |
boolean |
isSelected()
Returns true if this item is selected; otherwise, false is returned. |
boolean |
isUnderMouse()
Returns true if this item is currently under the mouse cursor in one of the views; otherwise, false is returned. |
boolean |
isVisible()
Returns true if the item is visible; otherwise, false is returned. |
boolean |
isVisibleTo(QGraphicsItemInterface parent)
Returns true if the item is visible to parent; otherwise, false is returned. |
boolean |
isWidget()
Returns true if this item is a widget (i. |
boolean |
isWindow()
Returns true if the item is a QGraphicsWidget window, otherwise returns false. |
java.lang.Object |
itemChange(QGraphicsItem.GraphicsItemChange change,
java.lang.Object value)
This virtual function is called by QGraphicsItem to notify custom items that some part of the item's state changes. |
QTransform |
itemTransform(QGraphicsItemInterface other)
Returns a QTransform that maps coordinates from this item to other. |
void |
keyPressEvent(QKeyEvent event)
This event handler, for event event, can be reimplemented to receive key press events for this item. |
void |
keyReleaseEvent(QKeyEvent event)
This event handler, for event event, can be reimplemented to receive key release events for this item. |
QPointF |
mapFromItem(QGraphicsItemInterface item,
double x,
double y)
This is an overloaded member function, provided for convenience. |
QPolygonF |
mapFromItem(QGraphicsItemInterface item,
double x,
double y,
double w,
double h)
This convenience function is equivalent to calling mapFromItem(item, QRectF (x, y, w, h)). |
QPainterPath |
mapFromItem(QGraphicsItemInterface item,
QPainterPath path)
Maps the path path, which is in item's coordinate system, to this item's coordinate system, and returns the mapped path. |
QPointF |
mapFromItem(QGraphicsItemInterface item,
QPointF point)
Maps the point point, which is in item's coordinate system, to this item's coordinate system, and returns the mapped coordinate. |
QPolygonF |
mapFromItem(QGraphicsItemInterface item,
QPolygonF polygon)
Maps the polygon polygon, which is in item's coordinate system, to this item's coordinate system, and returns the mapped polygon. |
QPolygonF |
mapFromItem(QGraphicsItemInterface item,
QRectF rect)
Maps the rectangle rect, which is in item's coordinate system, to this item's coordinate system, and returns the mapped rectangle as a polygon. |
QPointF |
mapFromParent(double x,
double y)
This is an overloaded member function, provided for convenience. |
QPolygonF |
mapFromParent(double x,
double y,
double w,
double h)
This convenience function is equivalent to calling mapFromItem( QRectF (x, y, w, h)). |
QPainterPath |
mapFromParent(QPainterPath path)
Maps the path path, which is in this item's parent's coordinate system, to this item's coordinate system, and returns the mapped path. |
QPointF |
mapFromParent(QPointF point)
Maps the point point, which is in this item's parent's coordinate system, to this item's coordinate system, and returns the mapped coordinate. |
QPolygonF |
mapFromParent(QPolygonF polygon)
Maps the polygon polygon, which is in this item's parent's coordinate system, to this item's coordinate system, and returns the mapped polygon. |
QPolygonF |
mapFromParent(QRectF rect)
Maps the rectangle rect, which is in this item's parent's coordinate system, to this item's coordinate system, and returns the mapped rectangle as a polygon. |
QPointF |
mapFromScene(double x,
double y)
This is an overloaded member function, provided for convenience. |
QPolygonF |
mapFromScene(double x,
double y,
double w,
double h)
This convenience function is equivalent to calling mapFromScene( QRectF (x, y, w, h)). |
QPainterPath |
mapFromScene(QPainterPath path)
Maps the path path, which is in this item's scene's coordinate system, to this item's coordinate system, and returns the mapped path. |
QPointF |
mapFromScene(QPointF point)
Maps the point point, which is in this item's scene's coordinate system, to this item's coordinate system, and returns the mapped coordinate. |
QPolygonF |
mapFromScene(QPolygonF polygon)
Maps the polygon polygon, which is in this item's scene's coordinate system, to this item's coordinate system, and returns the mapped polygon. |
QPolygonF |
mapFromScene(QRectF rect)
Maps the rectangle rect, which is in this item's scene's coordinate system, to this item's coordinate system, and returns the mapped rectangle as a polygon. |
QRectF |
mapRectFromItem(QGraphicsItemInterface item,
double x,
double y,
double w,
double h)
This convenience function is equivalent to calling mapRectFromItem(item, QRectF (x, y, w, h)). |
QRectF |
mapRectFromItem(QGraphicsItemInterface item,
QRectF rect)
Maps the rectangle rect, which is in item's coordinate system, to this item's coordinate system, and returns the mapped rectangle as a new rectangle (i. |
QRectF |
mapRectFromParent(double x,
double y,
double w,
double h)
This convenience function is equivalent to calling mapRectFromParent( QRectF (x, y, w, h)). |
QRectF |
mapRectFromParent(QRectF rect)
Maps the rectangle rect, which is in this item's parent's coordinate system, to this item's coordinate system, and returns the mapped rectangle as a new rectangle (i. |
QRectF |
mapRectFromScene(double x,
double y,
double w,
double h)
This convenience function is equivalent to calling mapRectFromScene( QRectF (x, y, w, h)). |
QRectF |
mapRectFromScene(QRectF rect)
Maps the rectangle rect, which is in scene coordinates, to this item's coordinate system, and returns the mapped rectangle as a new rectangle (i. |
QRectF |
mapRectToItem(QGraphicsItemInterface item,
double x,
double y,
double w,
double h)
This convenience function is equivalent to calling mapRectToItem(item, QRectF (x, y, w, h)). |
QRectF |
mapRectToItem(QGraphicsItemInterface item,
QRectF rect)
Maps the rectangle rect, which is in this item's coordinate system, to item's coordinate system, and returns the mapped rectangle as a new rectangle (i. |
QRectF |
mapRectToParent(double x,
double y,
double w,
double h)
This convenience function is equivalent to calling mapRectToParent( QRectF (x, y, w, h)). |
QRectF |
mapRectToParent(QRectF rect)
Maps the rectangle rect, which is in this item's coordinate system, to its parent's coordinate system, and returns the mapped rectangle as a new rectangle (i. |
QRectF |
mapRectToScene(double x,
double y,
double w,
double h)
This convenience function is equivalent to calling mapRectToScene( QRectF (x, y, w, h)). |
QRectF |
mapRectToScene(QRectF rect)
Maps the rectangle rect, which is in this item's coordinate system, to the scene coordinate system, and returns the mapped rectangle as a new rectangle (i. |
QPointF |
mapToItem(QGraphicsItemInterface item,
double x,
double y)
This is an overloaded member function, provided for convenience. |
QPolygonF |
mapToItem(QGraphicsItemInterface item,
double x,
double y,
double w,
double h)
This convenience function is equivalent to calling mapToItem(item, QRectF (x, y, w, h)). |
QPainterPath |
mapToItem(QGraphicsItemInterface item,
QPainterPath path)
Maps the path path, which is in this item's coordinate system, to item's coordinate system, and returns the mapped path. |
QPointF |
mapToItem(QGraphicsItemInterface item,
QPointF point)
Maps the point point, which is in this item's coordinate system, to item's coordinate system, and returns the mapped coordinate. |
QPolygonF |
mapToItem(QGraphicsItemInterface item,
QPolygonF polygon)
Maps the polygon polygon, which is in this item's coordinate system, to item's coordinate system, and returns the mapped polygon. |
QPolygonF |
mapToItem(QGraphicsItemInterface item,
QRectF rect)
Maps the rectangle rect, which is in this item's coordinate system, to item's coordinate system, and returns the mapped rectangle as a polygon. |
QPointF |
mapToParent(double x,
double y)
This is an overloaded member function, provided for convenience. |
QPolygonF |
mapToParent(double x,
double y,
double w,
double h)
This convenience function is equivalent to calling mapToParent( QRectF (x, y, w, h)). |
QPainterPath |
mapToParent(QPainterPath path)
Maps the path path, which is in this item's coordinate system, to its parent's coordinate system, and returns the mapped path. |
QPointF |
mapToParent(QPointF point)
Maps the point point, which is in this item's coordinate system, to its parent's coordinate system, and returns the mapped coordinate. |
QPolygonF |
mapToParent(QPolygonF polygon)
Maps the polygon polygon, which is in this item's coordinate system, to its parent's coordinate system, and returns the mapped polygon. |
QPolygonF |
mapToParent(QRectF rect)
Maps the rectangle rect, which is in this item's coordinate system, to its parent's coordinate system, and returns the mapped rectangle as a polygon. |
QPointF |
mapToScene(double x,
double y)
This is an overloaded member function, provided for convenience. |
QPolygonF |
mapToScene(double x,
double y,
double w,
double h)
This convenience function is equivalent to calling mapToScene( QRectF (x, y, w, h)). |
QPainterPath |
mapToScene(QPainterPath path)
Maps the path path, which is in this item's coordinate system, to the scene's coordinate system, and returns the mapped path. |
QPointF |
mapToScene(QPointF point)
Maps the point point, which is in this item's coordinate system, to the scene's coordinate system, and returns the mapped coordinate. |
QPolygonF |
mapToScene(QPolygonF polygon)
Maps the polygon polygon, which is in this item's coordinate system, to the scene's coordinate system, and returns the mapped polygon. |
QPolygonF |
mapToScene(QRectF rect)
Maps the rectangle rect, which is in this item's coordinate system, to the scene's coordinate system, and returns the mapped rectangle as a polygon. |
void |
mouseDoubleClickEvent(QGraphicsSceneMouseEvent event)
This event handler, for event event, can be reimplemented to receive mouse doubleclick events for this item. |
void |
mouseMoveEvent(QGraphicsSceneMouseEvent event)
This event handler, for event event, can be reimplemented to receive mouse move events for this item. |
void |
mousePressEvent(QGraphicsSceneMouseEvent event)
This event handler, for event event, can be reimplemented to receive mouse press events for this item. |
void |
mouseReleaseEvent(QGraphicsSceneMouseEvent event)
This event handler, for event event, can be reimplemented to receive mouse release events for this item. |
void |
moveBy(double dx,
double dy)
Moves the item by dx points horizontally, and dy point vertically. |
QPointF |
offset()
Returns the pixmap item's offset, which defines the point of the top-left corner of the pixmap, in local coordinates. |
double |
opacity()
Returns this item's local opacity, which is between 0. |
QPainterPath |
opaqueArea()
This virtual function returns a shape representing the area where this item is opaque. |
void |
paint(QPainter painter,
QStyleOptionGraphicsItem option,
QWidget widget)
This function, which is usually called by QGraphicsView , paints the contents of an item in local coordinates. |
QGraphicsItemInterface |
parentItem()
Returns a pointer to this item's parent item. |
QGraphicsWidget |
parentWidget()
Returns a pointer to the item's parent widget. |
QPixmap |
pixmap()
Returns the item's pixmap, or an invalid QPixmap if no pixmap has been set. |
QPointF |
pos()
Returns the position of the item in parent coordinates. |
void |
prepareGeometryChange()
Prepares the item for a geometry change. |
void |
removeSceneEventFilter(QGraphicsItemInterface filterItem)
Removes an event filter on this item from filterItem. |
void |
resetTransform()
Resets this item's transformation matrix to the identity matrix. |
void |
rotate(double angle)
Rotates the current item transformation angle degrees clockwise around its origin. |
void |
scale(double sx,
double sy)
Scales the current item transformation by (sx, sy) around its origin. |
QGraphicsScene |
scene()
Returns the current scene for the item, or 0 if the item is not stored in a scene. |
QRectF |
sceneBoundingRect()
Returns the bounding rect of this item in scene coordinates, by combining sceneTransform() with boundingRect() . |
boolean |
sceneEvent(QEvent event)
This virtual function receives events to this item. |
boolean |
sceneEventFilter(QGraphicsItemInterface watched,
QEvent event)
Filters events for the item watched. |
QPointF |
scenePos()
Returns the item's position in scene coordinates. |
QTransform |
sceneTransform()
Returns this item's scene transformation matrix. |
void |
scroll(double dx,
double dy,
QRectF rect)
Scrolls the contents of rect by dx, dy. |
void |
setAcceptDrops(boolean on)
If on is true, this item will accept drag and drop events; otherwise, it is transparent for drag and drop events. |
void |
setAcceptedMouseButtons(Qt.MouseButtons buttons)
Sets the mouse buttons that this item accepts mouse events for. |
void |
setAcceptHoverEvents(boolean enabled)
If enabled is true, this item will accept hover events; otherwise, it will ignore them. |
void |
setAcceptsHoverEvents(boolean enabled)
Use setAcceptHoverEvents(enabled) instead. |
void |
setBoundingRegionGranularity(double granularity)
Sets the bounding region granularity to granularity; a value between and including 0 and 1. |
void |
setCacheMode(QGraphicsItem.CacheMode mode,
QSize cacheSize)
Sets the item's cache mode to mode. |
void |
setCursor(QCursor cursor)
Sets the current cursor shape for the item to cursor. |
void |
setData(int key,
java.lang.Object value)
Sets this item's custom data for the key key to value. |
void |
setEnabled(boolean enabled)
If enabled is true, the item is enabled; otherwise, it is disabled. |
void |
setFlag(QGraphicsItem.GraphicsItemFlag flag,
boolean enabled)
If enabled is true, the item flag flag is enabled; otherwise, it is disabled. |
void |
setFlags(QGraphicsItem.GraphicsItemFlags flags)
Sets the item flags to flags. |
void |
setFocus(Qt.FocusReason focusReason)
Gives keyboard input focus to this item. |
void |
setGroup(QGraphicsItemGroup group)
Adds this item to the item group group. |
void |
setHandlesChildEvents(boolean enabled)
If enabled is true, this item is set to handle all events for all its children (i. |
void |
setOffset(double x,
double y)
This convenience function is equivalent to calling setOffset( QPointF (x, y)). |
void |
setOffset(QPointF offset)
Sets the pixmap item's offset to offset. |
void |
setOpacity(double opacity)
Sets this item's local opacity, between 0. |
void |
setParentItem(QGraphicsItemInterface parent)
Sets this item's parent item to parent. |
void |
setPixmap(QPixmap pixmap)
Sets the item's pixmap to pixmap. |
void |
setPos(double x,
double y)
This is an overloaded member function, provided for convenience. |
void |
setPos(QPointF pos)
Sets the position of the item to pos, which is in parent coordinates. |
void |
setSelected(boolean selected)
If selected is true and this item is selectable, this item is selected; otherwise, it is unselected. |
void |
setShapeMode(QGraphicsPixmapItem.ShapeMode mode)
Sets the item's shape mode to mode. |
void |
setToolTip(java.lang.String toolTip)
Sets the item's tool tip to toolTip. |
void |
setTransform(QTransform matrix,
boolean combine)
Sets the item's current transformation matrix to matrix. |
void |
setTransformationMode(Qt.TransformationMode mode)
Sets the pixmap item's transformation mode to mode, and toggles an update of the item. |
void |
setVisible(boolean visible)
If visible is true, the item is made visible. |
void |
setZValue(double z)
Sets the Z-value, or the elevation, of the item, to z. |
QPainterPath |
shape()
Returns the shape of this item as a QPainterPath in local coordinates. |
QGraphicsPixmapItem.ShapeMode |
shapeMode()
Returns the item's shape mode. |
void |
shear(double sh,
double sv)
Shears the current item transformation by (sh, sv). |
void |
show()
Shows the item. |
java.lang.String |
toolTip()
Returns the item's tool tip, or an empty QString if no tool tip has been set. |
QGraphicsItemInterface |
topLevelItem()
Returns this item's top-level item. |
QGraphicsWidget |
topLevelWidget()
Returns a pointer to the item's top level widget (i.e., the item's ancestor whose parent is 0, or whose parent is not a widget), or 0 if this item does not have a top level widget. |
QTransform |
transform()
Returns this item's transformation matrix. |
Qt.TransformationMode |
transformationMode()
Returns the transformation mode of the pixmap. |
void |
translate(double dx,
double dy)
Translates the current item transformation by (dx, dy). |
int |
type()
Returns the type of an item as an int. |
void |
ungrabKeyboard()
Releases the keyboard grab. |
void |
ungrabMouse()
Releases the mouse grab. |
void |
unsetCursor()
Clears the cursor from this item. |
void |
update(double x,
double y,
double width,
double height)
This is an overloaded member function, provided for convenience. |
void |
update(QRectF rect)
Schedules a redraw of the area covered by rect in this item. |
void |
wheelEvent(QGraphicsSceneWheelEvent event)
This event handler, for event event, can be reimplemented to receive wheel events for this item. |
QGraphicsWidget |
window()
Returns the item's window, or 0 if this item does not have a window. |
double |
x()
This convenience function is equivalent to calling pos() .x() . |
double |
y()
This convenience function is equivalent to calling pos() .y() . |
double |
zValue()
Returns the Z-value, or the elevation, of the item. |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
__qt_signalInitialization |
Methods inherited from class java.lang.Object |
---|
clone, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QGraphicsPixmapItem(QGraphicsItemInterface parent)
QGraphicsItem
's constructor.The item is then added to scene. QGraphicsScene::addItem()
.
public QGraphicsPixmapItem()
QGraphicsItem
's constructor.The item is then added to scene. QGraphicsScene::addItem()
.
public QGraphicsPixmapItem(QGraphicsItemInterface parent, QGraphicsScene scene)
QGraphicsItem
's constructor.The item is then added to scene. QGraphicsScene::addItem()
.
public QGraphicsPixmapItem(QPixmap pixmap, QGraphicsItemInterface parent)
public QGraphicsPixmapItem(QPixmap pixmap)
public QGraphicsPixmapItem(QPixmap pixmap, QGraphicsItemInterface parent, QGraphicsScene scene)
Method Detail |
---|
public final boolean acceptDrops()
setAcceptDrops()
.
acceptDrops
in interface QGraphicsItemInterface
public final boolean acceptHoverEvents()
QGraphicsSceneHoverEvent
); otherwise, returns false. By default, items do not accept hover events. setAcceptHoverEvents()
, and setAcceptedMouseButtons()
.
acceptHoverEvents
in interface QGraphicsItemInterface
public final Qt.MouseButtons acceptedMouseButtons()
If an item accepts a mouse button, it will become the mouse grabber item when a mouse press event is delivered for that mouse button. However, if the item does not accept the button, QGraphicsScene
will forward the mouse events to the first item beneath it that does.
setAcceptedMouseButtons()
, and mousePressEvent()
.
acceptedMouseButtons
in interface QGraphicsItemInterface
public final boolean acceptsHoverEvents()
acceptHoverEvents()
instead.
acceptsHoverEvents
in interface QGraphicsItemInterface
public final QRegion boundingRegion(QTransform itemToDeviceTransform)
QTransform
as a parameter, this function will return a local coordinate region. The bounding region describes a coarse outline of the item's visual contents. Although it's expensive to calculate, it's also more precise than boundingRect()
, and it can help to avoid unnecessary repainting when an item is updated. This is particularily efficient for thin items (e.g., lines or simple polygons). You can tune the granularity for the bounding region by calling setBoundingRegionGranularity()
. The default granularity is 0; in which the item's bounding region is the same as its bounding rect.
itemToDeviceTransform is the transformation from item coordinates to device coordinates. If you want this function to return a QRegion
in scene coordinates, you can pass sceneTransform()
as an argument.
boundingRegionGranularity()
.
boundingRegion
in interface QGraphicsItemInterface
public final double boundingRegionGranularity()
setBoundingRegionGranularity()
.
boundingRegionGranularity
in interface QGraphicsItemInterface
public final QGraphicsItem.CacheMode cacheMode()
NoCache
(i.e., cache is disabled and all painting is immediate). setCacheMode()
.
cacheMode
in interface QGraphicsItemInterface
public final java.util.List childItems()
setParentItem()
.
childItems
in interface QGraphicsItemInterface
public final QRectF childrenBoundingRect()
QRectF
. This does not include this item's own bounding rect; it only returns its descendants' accumulated bounding rect. If you need to include this item's bounding rect, you can add boundingRect()
to childrenBoundingRect()
using QRectF::operator|().
This function is linear in complexity; it determines the size of the returned bounding rect by iterating through all descendants.
boundingRect()
, and sceneBoundingRect()
.
childrenBoundingRect
in interface QGraphicsItemInterface
public final void clearFocus()
If it has focus, a focus out event is sent to this item to tell it that it is about to lose the focus.
Only items that set the ItemIsFocusable
flag, or widgets that set an appropriate focus policy, can accept keyboard focus.
setFocus()
, and QGraphicsWidget::focusPolicy
.
clearFocus
in interface QGraphicsItemInterface
public final QPainterPath clipPath()
QPainterPath
if this item is not clipped. The clip path constrains the item's appearance and interaction (i.e., restricts the area the item can draw, and it also restricts the area that the item receives events). You can enable clipping by setting the ItemClipsToShape
or ItemClipsChildrenToShape
flags. The item's clip path is calculated by intersecting all clipping ancestors' shapes. If the item sets ItemClipsToShape
, the final clip is intersected with the item's own shape.
Note: Clipping introduces a performance penalty for all items involved; you should generally avoid using clipping if you can (e.g., if your items always draw inside boundingRect()
or shape()
boundaries, clipping is not necessary).
isClipped()
, shape()
, and setFlags()
.
clipPath
in interface QGraphicsItemInterface
public final java.util.List collidingItems(Qt.ItemSelectionMode mode)
The way collisions are detected is determined by mode. The default value for mode is Qt::IntersectsItemShape
; All items whose shape intersects or is contained by this item's shape are returned.
QGraphicsScene::collidingItems()
, and collidesWithItem()
.
collidingItems
in interface QGraphicsItemInterface
public final QGraphicsItemInterface commonAncestorItem(QGraphicsItemInterface other)
isAncestorOf()
.
commonAncestorItem
in interface QGraphicsItemInterface
public final QCursor cursor()
list of predefined cursor objects
for a range of useful shapes. An editor item might want to use an I-beam cursor:
item.setCursor(new QCursor(Qt.CursorShape.IBeamCursor));If no cursor has been set, the parent's cursor is used.
setCursor()
, hasCursor()
, unsetCursor()
, QWidget::cursor
, and QApplication::overrideCursor()
.
cursor
in interface QGraphicsItemInterface
public final java.lang.Object data(int key)
QVariant
. Custom item data is useful for storing arbitrary properties in any item. Example:
int ObjectName = 0; QGraphicsItemInterface item = scene.itemAt(100, 50); if (item.data(ObjectName).toString().length() == 0) { if (item instanceof ButtonItem) item.setData(ObjectName, "Button"); }Qt does not use this feature for storing data; it is provided solely for the convenience of the user.
setData()
.
data
in interface QGraphicsItemInterface
public final QTransform deviceTransform(QTransform viewportTransform)
Example:
QGraphicsRectItem rect = new QGraphicsRectItem(); rect.setPos(100, 100); rect.deviceTransform(view.viewportTransform()).map(new QPointF(0, 0)); // returns the item's (0, 0) point in view's viewport coordinates rect.deviceTransform(view.viewportTransform()).inverted().map(new QPointF(100, 100)); // returns view's viewport's (100, 100) coordinate in item coordinatesThis function is the same as combining this item's scene transform with the view's viewport transform, but it also understands the
ItemIgnoresTransformations
flag. The device transform can be used to do accurate coordinate mapping (and collision detection) for untransformable items. transform()
, setTransform()
, scenePos()
, The Graphics View Coordinate System, and itemTransform()
.
deviceTransform
in interface QGraphicsItemInterface
public final double effectiveOpacity()
opacity()
, setOpacity()
, paint()
, ItemIgnoresParentOpacity
, and ItemDoesntPropagateOpacityToChildren
.
effectiveOpacity
in interface QGraphicsItemInterface
public final void ensureVisible(QRectF rect, int xmargin, int ymargin)
QGraphicsView
, this convenience function will attempt to scroll the view to ensure that rect is visible inside the view's viewport. If rect is a null rect (the default), QGraphicsItem
will default to the item's bounding rect. xmargin and ymargin are the number of pixels the view should use for margins. If the specified rect cannot be reached, the contents are scrolled to the nearest valid position.
If this item is not viewed by a QGraphicsView
, this function does nothing.
QGraphicsView::ensureVisible()
.
ensureVisible
in interface QGraphicsItemInterface
public final void ensureVisible(double x, double y, double w, double h, int xmargin, int ymargin)
QRectF
(x, y, w, h), xmargin, ymargin):
ensureVisible
in interface QGraphicsItemInterface
public final QGraphicsItem.GraphicsItemFlags flags()
ItemIsFocusable
, the item can accept input focus. By default, no flags are enabled.
setFlags()
, and setFlag()
.
flags
in interface QGraphicsItemInterface
public final void grabKeyboard()
The item will receive all keyboard input to the scene until one of the following events occur:
ungrabKeyboard()
grabKeyboard()
; the item will regain the keyboard grab when the other item calls ungrabKeyboard()
.QEvent::GrabKeyboard
event. When it loses the keyboard grab, it receives a QEvent::UngrabKeyboard
event. These events can be used to detect when your item gains or loses the keyboard grab through other means than gaining input focus. It is almost never necessary to explicitly grab the keyboard in Qt, as Qt grabs and releases it sensibly. In particular, Qt grabs the keyboard when your item gains input focus, and releases it when your item loses input focus, or when the item is hidden.
Note that only visible items can grab keyboard input. Calling grabKeyboard()
on an invisible item has no effect.
Keyboard events are not affected.
ungrabKeyboard()
, grabMouse()
, and setFocus()
.
grabKeyboard
in interface QGraphicsItemInterface
public final void grabMouse()
This item will receive all mouse events for the scene until any of the following events occurs:
ungrabMouse()
grabMouse()
; the item will regain the mouse grab when the other item calls ungrabMouse()
.QEvent::GrabMouse
event. When it loses the mouse grab, it receives a QEvent::UngrabMouse
event. These events can be used to detect when your item gains or loses the mouse grab through other means than receiving mouse button events. It is almost never necessary to explicitly grab the mouse in Qt, as Qt grabs and releases it sensibly. In particular, Qt grabs the mouse when you press a mouse button, and keeps the mouse grabbed until you release the last mouse button. Also, Qt::Popup
widgets implicitly call grabMouse()
when shown, and ungrabMouse()
when hidden.
Note that only visible items can grab mouse input. Calling grabMouse()
on an invisible item has no effect.
Keyboard events are not affected.
QGraphicsScene::mouseGrabberItem()
, ungrabMouse()
, and grabKeyboard()
.
grabMouse
in interface QGraphicsItemInterface
public final QGraphicsItemGroup group()
setGroup()
, QGraphicsItemGroup
, and QGraphicsScene::createItemGroup()
.
group
in interface QGraphicsItemInterface
public final boolean handlesChildEvents()
This property is useful for item groups; it allows one item to handle events on behalf of its children, as opposed to its children handling their events individually.
The default is to return false; children handle their own events. The exception for this is if the item is a QGraphicsItemGroup
, then it defaults to return true.
setHandlesChildEvents()
.
handlesChildEvents
in interface QGraphicsItemInterface
public final boolean hasCursor()
By default, items don't have any cursor set. cursor()
will return a standard pointing arrow cursor.
unsetCursor()
.
hasCursor
in interface QGraphicsItemInterface
public final boolean hasFocus()
QGraphicsScene::focusItem()
, setFocus()
, and QGraphicsScene::setFocusItem()
.
hasFocus
in interface QGraphicsItemInterface
public final void hide()
This convenience function is equivalent to calling setVisible(false).
show()
, and setVisible()
.
hide
in interface QGraphicsItemInterface
public final void installSceneEventFilter(QGraphicsItemInterface filterItem)
sceneEventFilter()
function. To filter another item's events, install this item as an event filter for the other item. Example:
QGraphicsScene scene = new QGraphicsScene(); QGraphicsEllipseItem ellipse = scene.addEllipse(new QRectF(-10, -10, 20, 20)); QGraphicsLineItem line = scene.addLine(new QLineF(-10, -10, 20, 20)); line.installSceneEventFilter(ellipse); // line's events are filtered by ellipse's sceneEventFilter() function. ellipse.installSceneEventFilter(line); // ellipse's events are filtered by line's sceneEventFilter() function.An item can only filter events for other items in the same scene. Also, an item cannot filter its own events; instead, you can reimplement
sceneEvent()
directly. Items must belong to a scene for scene event filters to be installed and used.
removeSceneEventFilter()
, sceneEventFilter()
, and sceneEvent()
.
installSceneEventFilter
in interface QGraphicsItemInterface
public final boolean isAncestorOf(QGraphicsItemInterface child)
parentItem()
.
isAncestorOf
in interface QGraphicsItemInterface
public final boolean isClipped()
ItemClipsToShape
flag, or if it or any of its ancestors has set the ItemClipsChildrenToShape
flag. Clipping affects the item's appearance (i.e., painting), as well as mouse and hover event delivery.
clipPath()
, shape()
, and setFlags()
.
isClipped
in interface QGraphicsItemInterface
public final boolean isEnabled()
setEnabled()
.
isEnabled
in interface QGraphicsItemInterface
public final boolean isObscured()
Its implementation is based on calling isObscuredBy()
, which you can reimplement to provide a custom obscurity algorithm.
opaqueArea()
.
isObscured
in interface QGraphicsItemInterface
public final boolean isObscured(QRectF rect)
Returns true if rect is completely obscured by the opaque shape of any of colliding items above it (i.e., with a higher Z value than this item).
Unlike the default isObscured()
function, this function does not call isObscuredBy()
.
opaqueArea()
.
isObscured
in interface QGraphicsItemInterface
public final boolean isObscured(double x, double y, double w, double h)
QRectF
(x, y, w, h)).
isObscured
in interface QGraphicsItemInterface
public final boolean isSelected()
Items that are in a group inherit the group's selected state.
Items are not selected by default.
setSelected()
, and QGraphicsScene::setSelectionArea()
.
isSelected
in interface QGraphicsItemInterface
public final boolean isUnderMouse()
QGraphicsScene::views()
, and QCursor::pos()
.
isUnderMouse
in interface QGraphicsItemInterface
public final boolean isVisible()
Note that the item's general visibility is unrelated to whether or not it is actually being visualized by a QGraphicsView
.
setVisible()
.
isVisible
in interface QGraphicsItemInterface
public final boolean isVisibleTo(QGraphicsItemInterface parent)
An item may not be visible to its ancestors even if isVisible()
is true. If any ancestor is hidden, the item itself will be implicitly hidden, in which case this function will return false.
isVisible()
, and setVisible()
.
isVisibleTo
in interface QGraphicsItemInterface
public final boolean isWidget()
QGraphicsWidget
); otherwise, returns false.
isWidget
in interface QGraphicsItemInterface
public final boolean isWindow()
QGraphicsWidget
window, otherwise returns false. QGraphicsWidget::windowFlags()
.
isWindow
in interface QGraphicsItemInterface
public final QTransform itemTransform(QGraphicsItemInterface other)
QTransform
that maps coordinates from this item to other. If ok is not null, and if there is no such transform, the boolean pointed to by ok will be set to false; otherwise true. This transform provides an alternative to the mapToItem()
or mapFromItem()
functions, by returning the appropriate transform so that you can map shapes and coordinates yourself. It also helps you write more efficient code when repeatedly mapping between the same two items.
Note that in rare circumstances, there is no transform that maps between two items
mapToItem()
, mapFromItem()
, and deviceTransform()
.
itemTransform
in interface QGraphicsItemInterface
public final QPainterPath mapFromItem(QGraphicsItemInterface item, QPainterPath path)
If item is 0, this function returns the same as mapFromScene()
.
itemTransform()
, mapFromParent()
, mapFromScene()
, mapToItem()
, and The Graphics View Coordinate System.
mapFromItem
in interface QGraphicsItemInterface
public final QPointF mapFromItem(QGraphicsItemInterface item, QPointF point)
If item is 0, this function returns the same as mapFromScene()
.
itemTransform()
, mapFromParent()
, mapFromScene()
, transform()
, mapToItem()
, and The Graphics View Coordinate System.
mapFromItem
in interface QGraphicsItemInterface
public final QPolygonF mapFromItem(QGraphicsItemInterface item, QPolygonF polygon)
If item is 0, this function returns the same as mapFromScene()
.
itemTransform()
, mapToItem()
, mapFromParent()
, transform()
, and The Graphics View Coordinate System.
mapFromItem
in interface QGraphicsItemInterface
public final QPolygonF mapFromItem(QGraphicsItemInterface item, QRectF rect)
If item is 0, this function returns the same as mapFromScene()
itemTransform()
, mapToItem()
, mapFromParent()
, transform()
, and The Graphics View Coordinate System.
mapFromItem
in interface QGraphicsItemInterface
public final QPointF mapFromItem(QGraphicsItemInterface item, double x, double y)
This convenience function is equivalent to calling mapFromItem(item, QPointF
(x, y)).
mapFromItem
in interface QGraphicsItemInterface
public final QPolygonF mapFromItem(QGraphicsItemInterface item, double x, double y, double w, double h)
QRectF
(x, y, w, h)).
mapFromItem
in interface QGraphicsItemInterface
public final QPainterPath mapFromParent(QPainterPath path)
mapFromScene()
, mapFromItem()
, mapToParent()
, and The Graphics View Coordinate System.
mapFromParent
in interface QGraphicsItemInterface
public final QPointF mapFromParent(QPointF point)
mapFromItem()
, mapFromScene()
, transform()
, mapToParent()
, and The Graphics View Coordinate System.
mapFromParent
in interface QGraphicsItemInterface
public final QPolygonF mapFromParent(QPolygonF polygon)
mapToParent()
, mapToItem()
, transform()
, and The Graphics View Coordinate System.
mapFromParent
in interface QGraphicsItemInterface
public final QPolygonF mapFromParent(QRectF rect)
mapToParent()
, mapFromItem()
, transform()
, and The Graphics View Coordinate System.
mapFromParent
in interface QGraphicsItemInterface
public final QPointF mapFromParent(double x, double y)
This convenience function is equivalent to calling mapFromParent(QPointF
(x, y)).
mapFromParent
in interface QGraphicsItemInterface
public final QPolygonF mapFromParent(double x, double y, double w, double h)
QRectF
(x, y, w, h)).
mapFromParent
in interface QGraphicsItemInterface
public final QPainterPath mapFromScene(QPainterPath path)
mapFromParent()
, mapFromItem()
, mapToScene()
, and The Graphics View Coordinate System.
mapFromScene
in interface QGraphicsItemInterface
public final QPointF mapFromScene(QPointF point)
mapFromItem()
, mapFromParent()
, transform()
, mapToScene()
, and The Graphics View Coordinate System.
mapFromScene
in interface QGraphicsItemInterface
public final QPolygonF mapFromScene(QPolygonF polygon)
mapToScene()
, mapFromParent()
, transform()
, and The Graphics View Coordinate System.
mapFromScene
in interface QGraphicsItemInterface
public final QPolygonF mapFromScene(QRectF rect)
mapToScene()
, mapFromItem()
, transform()
, and The Graphics View Coordinate System.
mapFromScene
in interface QGraphicsItemInterface
public final QPointF mapFromScene(double x, double y)
This convenience function is equivalent to calling mapFromScene(QPointF
(x, y)).
mapFromScene
in interface QGraphicsItemInterface
public final QPolygonF mapFromScene(double x, double y, double w, double h)
QRectF
(x, y, w, h)).
mapFromScene
in interface QGraphicsItemInterface
public final QRectF mapRectFromItem(QGraphicsItemInterface item, QRectF rect)
If item is 0, this function returns the same as mapRectFromScene()
.
itemTransform()
, mapToParent()
, mapToScene()
, mapFromItem()
, and The Graphics View Coordinate System.
mapRectFromItem
in interface QGraphicsItemInterface
public final QRectF mapRectFromItem(QGraphicsItemInterface item, double x, double y, double w, double h)
QRectF
(x, y, w, h)).
mapRectFromItem
in interface QGraphicsItemInterface
public final QRectF mapRectFromParent(QRectF rect)
itemTransform()
, mapToParent()
, mapToScene()
, mapFromItem()
, and The Graphics View Coordinate System.
mapRectFromParent
in interface QGraphicsItemInterface
public final QRectF mapRectFromParent(double x, double y, double w, double h)
QRectF
(x, y, w, h)).
mapRectFromParent
in interface QGraphicsItemInterface
public final QRectF mapRectFromScene(QRectF rect)
itemTransform()
, mapToParent()
, mapToScene()
, mapFromItem()
, and The Graphics View Coordinate System.
mapRectFromScene
in interface QGraphicsItemInterface
public final QRectF mapRectFromScene(double x, double y, double w, double h)
QRectF
(x, y, w, h)).
mapRectFromScene
in interface QGraphicsItemInterface
public final QRectF mapRectToItem(QGraphicsItemInterface item, QRectF rect)
If item is 0, this function returns the same as mapRectToScene()
.
itemTransform()
, mapToParent()
, mapToScene()
, mapFromItem()
, and The Graphics View Coordinate System.
mapRectToItem
in interface QGraphicsItemInterface
public final QRectF mapRectToItem(QGraphicsItemInterface item, double x, double y, double w, double h)
QRectF
(x, y, w, h)).
mapRectToItem
in interface QGraphicsItemInterface
public final QRectF mapRectToParent(QRectF rect)
itemTransform()
, mapToParent()
, mapToScene()
, mapFromItem()
, and The Graphics View Coordinate System.
mapRectToParent
in interface QGraphicsItemInterface
public final QRectF mapRectToParent(double x, double y, double w, double h)
QRectF
(x, y, w, h)).
mapRectToParent
in interface QGraphicsItemInterface
public final QRectF mapRectToScene(QRectF rect)
itemTransform()
, mapToParent()
, mapToScene()
, mapFromItem()
, and The Graphics View Coordinate System.
mapRectToScene
in interface QGraphicsItemInterface
public final QRectF mapRectToScene(double x, double y, double w, double h)
QRectF
(x, y, w, h)).
mapRectToScene
in interface QGraphicsItemInterface
public final QPainterPath mapToItem(QGraphicsItemInterface item, QPainterPath path)
If item is 0, this function returns the same as mapToScene()
.
itemTransform()
, mapToParent()
, mapToScene()
, mapFromItem()
, and The Graphics View Coordinate System.
mapToItem
in interface QGraphicsItemInterface
public final QPointF mapToItem(QGraphicsItemInterface item, QPointF point)
If item is 0, this function returns the same as mapToScene()
.
itemTransform()
, mapToParent()
, mapToScene()
, transform()
, mapFromItem()
, and The Graphics View Coordinate System.
mapToItem
in interface QGraphicsItemInterface
public final QPolygonF mapToItem(QGraphicsItemInterface item, QPolygonF polygon)
If item is 0, this function returns the same as mapToScene()
.
itemTransform()
, mapToParent()
, mapToScene()
, mapFromItem()
, and The Graphics View Coordinate System.
mapToItem
in interface QGraphicsItemInterface
public final QPolygonF mapToItem(QGraphicsItemInterface item, QRectF rect)
If item is 0, this function returns the same as mapToScene()
.
itemTransform()
, mapToParent()
, mapToScene()
, mapFromItem()
, and The Graphics View Coordinate System.
mapToItem
in interface QGraphicsItemInterface
public final QPointF mapToItem(QGraphicsItemInterface item, double x, double y)
This convenience function is equivalent to calling mapToItem(item, QPointF
(x, y)).
mapToItem
in interface QGraphicsItemInterface
public final QPolygonF mapToItem(QGraphicsItemInterface item, double x, double y, double w, double h)
QRectF
(x, y, w, h)).
mapToItem
in interface QGraphicsItemInterface
public final QPainterPath mapToParent(QPainterPath path)
mapToScene()
, mapToItem()
, mapFromParent()
, and The Graphics View Coordinate System.
mapToParent
in interface QGraphicsItemInterface
public final QPointF mapToParent(QPointF point)
mapToItem()
, mapToScene()
, transform()
, mapFromParent()
, and The Graphics View Coordinate System.
mapToParent
in interface QGraphicsItemInterface
public final QPolygonF mapToParent(QPolygonF polygon)
mapToScene()
, mapToItem()
, mapFromParent()
, and The Graphics View Coordinate System.
mapToParent
in interface QGraphicsItemInterface
public final QPolygonF mapToParent(QRectF rect)
mapToScene()
, mapToItem()
, mapFromParent()
, and The Graphics View Coordinate System.
mapToParent
in interface QGraphicsItemInterface
public final QPointF mapToParent(double x, double y)
This convenience function is equivalent to calling mapToParent(QPointF
(x, y)).
mapToParent
in interface QGraphicsItemInterface
public final QPolygonF mapToParent(double x, double y, double w, double h)
QRectF
(x, y, w, h)).
mapToParent
in interface QGraphicsItemInterface
public final QPainterPath mapToScene(QPainterPath path)
mapToParent()
, mapToItem()
, mapFromScene()
, and The Graphics View Coordinate System.
mapToScene
in interface QGraphicsItemInterface
public final QPointF mapToScene(QPointF point)
mapToItem()
, mapToParent()
, transform()
, mapFromScene()
, and The Graphics View Coordinate System.
mapToScene
in interface QGraphicsItemInterface
public final QPolygonF mapToScene(QPolygonF polygon)
mapToParent()
, mapToItem()
, mapFromScene()
, and The Graphics View Coordinate System.
mapToScene
in interface QGraphicsItemInterface
public final QPolygonF mapToScene(QRectF rect)
mapToParent()
, mapToItem()
, mapFromScene()
, and The Graphics View Coordinate System.
mapToScene
in interface QGraphicsItemInterface
public final QPointF mapToScene(double x, double y)
This convenience function is equivalent to calling mapToScene(QPointF
(x, y)).
mapToScene
in interface QGraphicsItemInterface
public final QPolygonF mapToScene(double x, double y, double w, double h)
QRectF
(x, y, w, h)).
mapToScene
in interface QGraphicsItemInterface
public final void moveBy(double dx, double dy)
pos()
+ QPointF
(dx, dy)).
moveBy
in interface QGraphicsItemInterface
public final QPointF offset()
setOffset()
.
public final double opacity()
effectiveOpacity()
. The effective opacity decides how the item is rendered. The opacity property decides the state of the painter passed to the paint()
function. If the item is cached (i.e., ItemCoordinateCache
or DeviceCoordinateCache
), the effective property will applied to the item's cache as it is rendered.
The default opacity is 1.0; fully opaque.
setOpacity()
, paint()
, ItemIgnoresParentOpacity
, and ItemDoesntPropagateOpacityToChildren
.
opacity
in interface QGraphicsItemInterface
public final QGraphicsItemInterface parentItem()
setParentItem()
, and children().
parentItem
in interface QGraphicsItemInterface
public final QGraphicsWidget parentWidget()
parentItem()
, and childItems()
.
parentWidget
in interface QGraphicsItemInterface
public final QPixmap pixmap()
QPixmap
if no pixmap has been set. setPixmap()
.
public final QPointF pos()
The position of the item describes its origin (local coordinate (0, 0)) in parent coordinates; this function returns the same as mapToParent(0, 0).
For convenience, you can also call scenePos()
to determine the item's position in scene coordinates, regardless of its parent.
x()
, y()
, setPos()
, matrix(), and The Graphics View Coordinate System.
pos
in interface QGraphicsItemInterface
public final void prepareGeometryChange()
QGraphicsScene
's index up to date. prepareGeometryChange()
will call update()
if this is necessary.
Example:
public class CircleItem extends QGraphicsItem { // ... public void setRadius(double newRadius) { if (radius != newRadius) { prepareGeometryChange(); radius = newRadius; } } }
boundingRect()
.
prepareGeometryChange
in interface QGraphicsItemInterface
public final void removeSceneEventFilter(QGraphicsItemInterface filterItem)
installSceneEventFilter()
.
removeSceneEventFilter
in interface QGraphicsItemInterface
public final void resetTransform()
setTransform()
, and transform()
.
resetTransform
in interface QGraphicsItemInterface
public final void rotate(double angle)
setTransform()
. Example:
// Rotate an item 45 degrees around (0, 0). item.rotate(45); // Rotate an item 45 degrees around (x, y). item.setTransform(new QTransform().translate(x, y).rotate(45).translate(-x, -y));
setTransform()
, transform()
, scale()
, shear()
, and translate()
.
rotate
in interface QGraphicsItemInterface
public final void scale(double sx, double sy)
setTransform()
. Example:
// Scale an item by 3x2 from its origin item.scale(3, 2); // Scale an item by 3x2 from (x, y) item.setTransform(new QTransform().translate(x, y).scale(3, 2).translate(-x, -y));
setTransform()
, transform()
, rotate()
, shear()
, and translate()
.
scale
in interface QGraphicsItemInterface
public final QGraphicsScene scene()
To add or move an item to a scene, call QGraphicsScene::addItem()
.
scene
in interface QGraphicsItemInterface
public final QRectF sceneBoundingRect()
sceneTransform()
with boundingRect()
. boundingRect()
, and The Graphics View Coordinate System.
sceneBoundingRect
in interface QGraphicsItemInterface
public final QPointF scenePos()
pos()
, sceneTransform()
, and The Graphics View Coordinate System.
scenePos
in interface QGraphicsItemInterface
public final QTransform sceneTransform()
Example:
QGraphicsRectItem rect = new QGraphicsRectItem(); rect.setPos(100, 100); rect.sceneTransform().map(new QPointF(0, 0)); // returns QPointF(100, 100); rect.sceneTransform().inverted().map(new QPointF(100, 100)); // returns QPointF(0, 0);Unlike
transform()
, which returns only an item's local transformation, this function includes the item's (and any parents') position. transform()
, setTransform()
, scenePos()
, and The Graphics View Coordinate System.
sceneTransform
in interface QGraphicsItemInterface
public final void scroll(double dx, double dy, QRectF rect)
Scrolling provides a fast alternative to simply redrawing when the contents of the item (or parts of the item) are shifted vertically or horizontally. Depending on the current transformation and the capabilities of the paint device (i.e., the viewport), this operation may consist of simply moving pixels from one location to another using memmove(). In most cases this is faster than rerendering the entire area.
After scrolling, the item will issue an update for the newly exposed areas. If scrolling is not supported (e.g., you are rendering to an OpenGL viewport, which does not benefit from scroll optimizations), this function is equivalent to calling update(rect).
boundingRect()
.
scroll
in interface QGraphicsItemInterface
public final void setAcceptDrops(boolean on)
acceptDrops()
.
setAcceptDrops
in interface QGraphicsItemInterface
public final void setAcceptHoverEvents(boolean enabled)
Hover events are delivered when there is no current mouse grabber item. They are sent when the mouse cursor enters an item, when it moves around inside the item, and when the cursor leaves an item. Hover events are commonly used to highlight an item when it's entered, and for tracking the mouse cursor as it hovers over the item (equivalent to QWidget::mouseTracking
).
Parent items receive hover enter events before their children, and leave events after their children. The parent does not receive a hover leave event if the cursor enters a child, though; the parent stays "hovered" until the cursor leaves its area, including its children's areas.
If a parent item handles child events (setHandlesChildEvents()
), it will receive hover move, drag move, and drop events as the cursor passes through its children, but it does not receive hover enter and hover leave, nor drag enter and drag leave events on behalf of its children.
A QGraphicsWidget
with window decorations will accept hover events regardless of the value of acceptHoverEvents()
.
acceptHoverEvents()
, hoverEnterEvent()
, hoverMoveEvent()
, and hoverLeaveEvent()
.
setAcceptHoverEvents
in interface QGraphicsItemInterface
public final void setAcceptedMouseButtons(Qt.MouseButtons buttons)
By default, all mouse buttons are accepted. If an item accepts a mouse button, it will become the mouse grabber item when a mouse press event is delivered for that button. However, if the item does not accept the mouse button, QGraphicsScene
will forward the mouse events to the first item beneath it that does.
To disable mouse events for an item (i.e., make it transparent for mouse events), call setAcceptedMouseButtons(0).
acceptedMouseButtons()
, and mousePressEvent()
.
setAcceptedMouseButtons
in interface QGraphicsItemInterface
public final void setAcceptsHoverEvents(boolean enabled)
setAcceptsHoverEvents
in interface QGraphicsItemInterface
public final void setBoundingRegionGranularity(double granularity)
The granularity is used by boundingRegion()
to calculate how fine the bounding region of the item should be. The highest achievable granularity is 1, where boundingRegion()
will return the finest outline possible for the respective device (e.g., for a QGraphicsView
viewport, this gives you a pixel-perfect bounding region). The lowest possible granularity is 0. The value of granularity describes the ratio between device resolution and the resolution of the bounding region (e.g., a value of 0.25 will provide a region where each chunk corresponds to 4x4 device units / pixels).
boundingRegionGranularity()
.
setBoundingRegionGranularity
in interface QGraphicsItemInterface
public final void setCacheMode(QGraphicsItem.CacheMode mode, QSize cacheSize)
The optional logicalCacheSize argument is used only by ItemCoordinateCache
mode, and describes the resolution of the cache buffer; if logicalCacheSize is (100, 100), QGraphicsItem
will fit the item into 100x100 pixels in graphics memory, regardless of the logical size of the item itself. By default QGraphicsItem
uses the size of boundingRect()
. For all other cache modes than ItemCoordinateCache
, logicalCacheSize is ignored.
Caching can speed up rendering if your item spends a significant time redrawing itself. In some cases the cache can also slow down rendering, in particular when the item spends less time redrawing than QGraphicsItem
spends redrawing from the cache. When enabled, the item's paint()
function will be called only once for each call to update()
; for any subsequent repaint requests, the Graphics View framework will redraw from the cache. This approach works particularly well with QGLWidget
, which stores all the cache as OpenGL textures.
Be aware that QPixmapCache
's cache limit may need to be changed to obtain optimal performance.
You can read more about the different cache modes in the CacheMode
documentation.
cacheMode()
, CacheMode
, and QPixmapCache::setCacheLimit()
.
setCacheMode
in interface QGraphicsItemInterface
public final void setCursor(QCursor cursor)
list of predefined cursor objects
for a range of useful shapes. An editor item might want to use an I-beam cursor:
item.setCursor(new QCursor(Qt.CursorShape.IBeamCursor));If no cursor has been set, the cursor of the item beneath is used.
cursor()
, hasCursor()
, unsetCursor()
, QWidget::cursor
, and QApplication::overrideCursor()
.
setCursor
in interface QGraphicsItemInterface
public final void setData(int key, java.lang.Object value)
Custom item data is useful for storing arbitrary properties for any item. Qt does not use this feature for storing data; it is provided solely for the convenience of the user.
data()
.
setData
in interface QGraphicsItemInterface
public final void setEnabled(boolean enabled)
Disabled items are visible, but they do not receive any events, and cannot take focus nor be selected. Mouse events are discarded; they are not propagated unless the item is also invisible, or if it does not accept mouse events (see acceptedMouseButtons()
). A disabled item cannot become the mouse grabber, and as a result of this, an item loses the grab if it becomes disabled when grabbing the mouse, just like it loses focus if it had focus when it was disabled.
Disabled items are traditionally drawn using grayed-out colors (see QPalette::Disabled
).
If you disable a parent item, all its children will also be disabled. If you enable a parent item, all children will be enabled, unless they have been explicitly disabled (i.e., if you call setEnabled(false) on a child, it will not be reenabled if its parent is disabled, and then enabled again).
Items are enabled by default.
Note: If you install an event filter, you can still intercept events before they are delivered to items; this mechanism disregards the item's enabled state.
isEnabled()
.
setEnabled
in interface QGraphicsItemInterface
public final void setFlag(QGraphicsItem.GraphicsItemFlag flag, boolean enabled)
flags()
, and setFlags()
.
setFlag
in interface QGraphicsItemInterface
public final void setFlags(QGraphicsItem.GraphicsItemFlags flags)
If the item had focus and flags does not enable ItemIsFocusable
, the item loses focus as a result of calling this function. Similarly, if the item was selected, and flags does not enabled ItemIsSelectable
, the item is automatically unselected.
By default, no flags are enabled.
flags()
, and setFlag()
.
setFlags
in interface QGraphicsItemInterface
public final void setFocus(Qt.FocusReason focusReason)
Only items that set the ItemIsFocusable
flag can accept keyboard focus.
If this item is not visible (i.e., isVisible()
returns false), not enabled, not associated with a scene, or if it already has input focus, this function will do nothing.
As a result of calling this function, this item will receive a focus in event with focusReason. If another item already has focus, that item will first receive a focus out event indicating that it has lost input focus.
clearFocus()
, and hasFocus()
.
setFocus
in interface QGraphicsItemInterface
public final void setGroup(QGraphicsItemGroup group)
group()
, and QGraphicsScene::createItemGroup()
.
setGroup
in interface QGraphicsItemInterface
public final void setHandlesChildEvents(boolean enabled)
This property is useful for item groups; it allows one item to handle events on behalf of its children, as opposed to its children handling their events individually.
If a child item accepts hover events, its parent will receive hover move events as the cursor passes through the child, but it does not receive hover enter and hover leave events on behalf of its child.
handlesChildEvents()
.
setHandlesChildEvents
in interface QGraphicsItemInterface
public final void setOffset(QPointF offset)
offset()
.
public final void setOffset(double x, double y)
QPointF
(x, y)).
public final void setOpacity(double opacity)
effectiveOpacity()
. By default, opacity propagates from parent to child, so if a parent's opacity is 0.5 and the child is also 0.5, the child's effective opacity will be 0.25. The result
The opacity property decides the state of the painter passed to the paint()
function. If the item is cached (i.e., ItemCoordinateCache
or DeviceCoordinateCache
), the effective property will applied to the item's cache as it is rendered.
There are two item flags that affect how the item's opacity is combined with the parent: ItemIgnoresParentOpacity
and ItemDoesntPropagateOpacityToChildren
.
opacity()
, and effectiveOpacity()
.
setOpacity
in interface QGraphicsItemInterface
public final void setParentItem(QGraphicsItemInterface parent)
parentItem()
, and children().
setParentItem
in interface QGraphicsItemInterface
public final void setPixmap(QPixmap pixmap)
pixmap()
.
public final void setPos(QPointF pos)
The position of the item describes its origin (local coordinate (0, 0)) in parent coordinates.
pos()
, scenePos()
, and The Graphics View Coordinate System.
setPos
in interface QGraphicsItemInterface
public final void setPos(double x, double y)
This convenience function is equivalent to calling setPos(QPointF
(x, y)).
setPos
in interface QGraphicsItemInterface
public final void setSelected(boolean selected)
If the item is in a group, the whole group's selected state is toggled by this function. If the group is selected, all items in the group are also selected, and if the group is not selected, no item in the group is selected.
Only visible, enabled, selectable items can be selected. If selected is true and this item is either invisible or disabled or unselectable, this function does nothing.
By default, items cannot be selected. To enable selection, set the ItemIsSelectable
flag.
This function is provided for convenience, allowing individual toggling of the selected state of an item. However, a more common way of selecting items is to call QGraphicsScene::setSelectionArea()
, which will call this function for all visible, enabled, and selectable items within a specified area on the scene.
isSelected()
, and QGraphicsScene::selectedItems()
.
setSelected
in interface QGraphicsItemInterface
public final void setShapeMode(QGraphicsPixmapItem.ShapeMode mode)
MaskShape
. shapeMode()
, and ShapeMode
.
public final void setToolTip(java.lang.String toolTip)
toolTip()
, and QToolTip
.
setToolTip
in interface QGraphicsItemInterface
public final void setTransform(QTransform matrix, boolean combine)
If combine is true, then matrix is combined with the current matrix; otherwise, matrixreplaces the current matrix. combine is false by default.
To simplify interation with items using a transformed view, QGraphicsItem
provides mapTo... and mapFrom... functions that can translate between items' and the scene's coordinates. For example, you can call mapToScene()
to map an item coordiate to a scene coordinate, or mapFromScene()
to map from scene coordinates to item coordinates.
transform()
, rotate()
, scale()
, shear()
, translate()
, and The Graphics View Coordinate System.
setTransform
in interface QGraphicsItemInterface
public final void setTransformationMode(Qt.TransformationMode mode)
Qt::FastTransformation
, which provides quick transformation with no smoothing. Qt::SmoothTransformation
enables QPainter::SmoothPixmapTransform
on the painter, and the quality depends on the platform and viewport. The result is usually not as good as calling QPixmap::scale() directly.
transformationMode()
.
public final void setVisible(boolean visible)
QGraphicsScene
's item location functions. If an item becomes invisible while grabbing the mouse, (i.e., while it is receiving mouse events,) it will automatically lose the mouse grab, and the grab is not regained by making the item visible again; it must receive a new mouse press to regain the mouse grab.
Similarly, an invisible item cannot have focus, so if the item has focus when it becomes invisible, it will lose focus, and the focus is not regained by simply making the item visible again.
If you hide a parent item, all its children will also be hidden. If you show a parent item, all children will be shown, unless they have been explicitly hidden (i.e., if you call setVisible(false) on a child, it will not be reshown even if its parent is hidden, and then shown again).
Items are visible by default; it is unnecessary to call setVisible()
on a new item.
isVisible()
, show()
, and hide()
.
setVisible
in interface QGraphicsItemInterface
public final void setZValue(double z)
The Z-value does not affect the item's size in any way.
The default Z-value is 0.
zValue()
.
setZValue
in interface QGraphicsItemInterface
public final QGraphicsPixmapItem.ShapeMode shapeMode()
MaskShape
. setShapeMode()
, and ShapeMode
.
public final void shear(double sh, double sv)
setTransform()
, transform()
, rotate()
, scale()
, and translate()
.
shear
in interface QGraphicsItemInterface
public final void show()
This convenience function is equivalent to calling setVisible(true).
hide()
, and setVisible()
.
show
in interface QGraphicsItemInterface
public final java.lang.String toolTip()
setToolTip()
, and QToolTip
.
toolTip
in interface QGraphicsItemInterface
public final QGraphicsItemInterface topLevelItem()
parentItem()
.
topLevelItem
in interface QGraphicsItemInterface
public final QGraphicsWidget topLevelWidget()
topLevelWidget
in interface QGraphicsItemInterface
public final QTransform transform()
setTransform()
, and sceneTransform()
.
transform
in interface QGraphicsItemInterface
public final Qt.TransformationMode transformationMode()
Qt::FastTransformation
, which provides quick transformation with no smoothing. setTransformationMode()
.
public final void translate(double dx, double dy)
If all you want is to move an item, you should call moveBy()
or setPos()
instead; this function changes the item's translation, which is conceptually separate from its position.
setTransform()
, transform()
, rotate()
, scale()
, and shear()
.
translate
in interface QGraphicsItemInterface
public final void ungrabKeyboard()
grabKeyboard()
, and ungrabMouse()
.
ungrabKeyboard
in interface QGraphicsItemInterface
public final void ungrabMouse()
grabMouse()
, and ungrabKeyboard()
.
ungrabMouse
in interface QGraphicsItemInterface
public final void unsetCursor()
hasCursor()
, and setCursor()
.
unsetCursor
in interface QGraphicsItemInterface
public final void update(QRectF rect)
This function does not cause an immediate paint; instead it schedules a paint request that is processed by QGraphicsView
after control reaches the event loop. The item will only be redrawn if it is visible in any associated view.
As a side effect of the item being repainted, other items that overlap the area rect may also be repainted.
If the item is invisible (i.e., isVisible()
returns false), this function does nothing.
paint()
, and boundingRect()
.
update
in interface QGraphicsItemInterface
public final void update(double x, double y, double width, double height)
This convenience function is equivalent to calling update(QRectF
(x, y, width, height)).
update
in interface QGraphicsItemInterface
public final QGraphicsWidget window()
QGraphicsWidget::isWindow()
.
window
in interface QGraphicsItemInterface
public final double x()
pos()
.x()
. y()
.
x
in interface QGraphicsItemInterface
public final double y()
pos()
.y()
. x()
.
y
in interface QGraphicsItemInterface
public final double zValue()
The default Z-value is 0.
setZValue()
.
zValue
in interface QGraphicsItemInterface
public void advance(int phase)
QGraphicsScene::advance()
slot. In the first phase, all items are called with phase == 0, indicating that items on the scene are about to advance, and then all items are called with phase == 1. Reimplement this function to update your item if you need simple scene-controlled animation. The default implementation does nothing.
For individual item animation, an alternative to this function is to either use QGraphicsItemAnimation
, or to multiple-inherit from QObject
and QGraphicsItem
, and animate your item using QObject::startTimer()
and QObject::timerEvent()
.
QGraphicsItemAnimation
, and QTimeLine
.
advance
in interface QGraphicsItemInterface
public QRectF boundingRect()
QGraphicsView
uses this to determine whether the item requires redrawing. Although the item's shape can be arbitrary, the bounding rect is always rectangular, and it is unaffected by the items' transformation (scale()
, rotate()
, etc.).
If you want to change the item's bounding rectangle, you must first call prepareGeometryChange()
. This notifies the scene of the imminent change, so that its can update its item geometry index; otherwise, the scene will be unaware of the item's new geometry, and the results are undefined (typically, rendering artifacts are left around in the view).
Reimplement this function to let QGraphicsView
determine what parts of the widget, if any, need to be redrawn.
Note: For shapes that paint an outline / stroke, it is important to include half the pen width in the bounding rect. It is not necessary to compensate for antialiasing, though.
Example:
public class CircleItem extends QGraphicsItem { // ... public QRectF boundingRect() { double penWidth = 1; return new QRectF(-radius - penWidth / 2, -radius - penWidth / 2, diameter + penWidth, diameter + penWidth); } // ... }
boundingRegion()
, shape()
, contains()
, The Graphics View Coordinate System, and prepareGeometryChange()
.
boundingRect
in interface QGraphicsItemInterface
public boolean collidesWithItem(QGraphicsItemInterface other, Qt.ItemSelectionMode mode)
Qt::IntersectsItemShape
; other collides with this item if it either intersects, contains, or is contained by this item's shape. The default implementation is based on shape intersection, and it calls shape()
on both items. Because the complexity of arbitrary shape-shape intersection grows with an order of magnitude when the shapes are complex, this operation can be noticably time consuming. You have the option of reimplementing this function in a subclass of QGraphicsItem
to provide a custom algorithm. This allows you to make use of natural constraints in the shapes of your own items, in order to improve the performance of the collision detection. For instance, two untransformed perfectly circular items' collision can be determined very efficiently by comparing their positions and radii.
Keep in mind that when reimplementing this function and calling shape()
or boundingRect()
on other, the returned coordinates must be mapped to this item's coordinate system before any intersection can take place.
contains()
, and shape()
.
collidesWithItem
in interface QGraphicsItemInterface
public boolean collidesWithPath(QPainterPath path, Qt.ItemSelectionMode mode)
The collision is determined by mode. The default value for mode is Qt::IntersectsItemShape
; path collides with this item if it either intersects, contains, or is contained by this item's shape.
collidesWithItem()
, contains()
, and shape()
.
collidesWithPath
in interface QGraphicsItemInterface
public boolean contains(QPointF point)
QGraphicsView
to determine what item is under the cursor, and for that reason, the implementation of this function should be as light-weight as possible. By default, this function calls shape()
, but you can reimplement it in a subclass to provide a (perhaps more efficient) implementation.
shape()
, boundingRect()
, and collidesWithPath()
.
contains
in interface QGraphicsItemInterface
public void contextMenuEvent(QGraphicsSceneContextMenuEvent event)
If you ignore the event, (i.e., by calling QEvent::ignore()
,) event will propagate to any item beneath this item. If no items accept the event, it will be ignored by the scene, and propagate to the view.
It's common to open a QMenu
in response to receiving a context menu event. Example:
public class CutsomItem extends QGraphicsItem { // ... public void contextMenuEvent(QGraphicsSceneContextMenuEvent event) { QMenu menu = new QMenu(); QAction emoveAction = menu.addAction("Remove"); QAction arkAction = menu.addAction("Mark"); QAction electedAction = menu.exec(event.screenPos()); // ... } // ... }The default implementation ignores the event.
sceneEvent()
.
contextMenuEvent
in interface QGraphicsItemInterface
public void dragEnterEvent(QGraphicsSceneDragDropEvent event)
By accepting the event, (i.e., by calling QEvent::accept()
,) the item will accept drop events, in addition to receiving drag move and drag leave. Otherwise, the event will be ignored and propagate to the item beneath. If the event is accepted, the item will receive a drag move event before control goes back to the event loop.
A common implementation of dragEnterEvent accepts or ignores event depending on the associated mime data in event. Example:
public class CutsomItem extends QGraphicsItem { public CutsomItem() { setAcceptDrops(true); // ... } public void dragEnterEvent(QGraphicsSceneDragDropEvent event) { event.setAccepted(event.mimeData().hasFormat("text/plain")); } // ... }Items do not receive drag and drop events by default; to enable this feature, call setAcceptDrops(true).
The default implementation does nothing.
dropEvent()
, dragMoveEvent()
, and dragLeaveEvent()
.
dragEnterEvent
in interface QGraphicsItemInterface
public void dragLeaveEvent(QGraphicsSceneDragDropEvent event)
Calling QEvent::ignore()
or QEvent::accept()
on event has no effect.
Items do not receive drag and drop events by default; to enable this feature, call setAcceptDrops(true).
The default implementation does nothing.
dragEnterEvent()
, dropEvent()
, and dragMoveEvent()
.
dragLeaveEvent
in interface QGraphicsItemInterface
public void dragMoveEvent(QGraphicsSceneDragDropEvent event)
Calling QEvent::ignore()
or QEvent::accept()
on event toggles whether or not the item will accept drops at the position from the event. By default, event is accepted, indicating that the item allows drops at the specified position.
Items do not receive drag and drop events by default; to enable this feature, call setAcceptDrops(true).
The default implementation does nothing.
dropEvent()
, dragEnterEvent()
, and dragLeaveEvent()
.
dragMoveEvent
in interface QGraphicsItemInterface
public void dropEvent(QGraphicsSceneDragDropEvent event)
Calling QEvent::ignore()
or QEvent::accept()
on event has no effect.
Items do not receive drag and drop events by default; to enable this feature, call setAcceptDrops(true).
The default implementation does nothing.
dragEnterEvent()
, dragMoveEvent()
, and dragLeaveEvent()
.
dropEvent
in interface QGraphicsItemInterface
public void focusInEvent(QFocusEvent event)
ensureVisible()
. focusOutEvent()
, and sceneEvent()
.
focusInEvent
in interface QGraphicsItemInterface
public void focusOutEvent(QFocusEvent event)
focusInEvent()
, and sceneEvent()
.
focusOutEvent
in interface QGraphicsItemInterface
public void hoverEnterEvent(QGraphicsSceneHoverEvent event)
update()
; otherwise it does nothing. Calling QEvent::ignore()
or QEvent::accept()
on event has no effect.
hoverMoveEvent()
, hoverLeaveEvent()
, sceneEvent()
, and setAcceptHoverEvents()
.
hoverEnterEvent
in interface QGraphicsItemInterface
public void hoverLeaveEvent(QGraphicsSceneHoverEvent event)
update()
; otherwise it does nothing. Calling QEvent::ignore()
or QEvent::accept()
on event has no effect.
hoverEnterEvent()
, hoverMoveEvent()
, sceneEvent()
, and setAcceptHoverEvents()
.
hoverLeaveEvent
in interface QGraphicsItemInterface
public void hoverMoveEvent(QGraphicsSceneHoverEvent event)
Calling QEvent::ignore()
or QEvent::accept()
on event has no effect.
hoverEnterEvent()
, hoverLeaveEvent()
, sceneEvent()
, and setAcceptHoverEvents()
.
hoverMoveEvent
in interface QGraphicsItemInterface
public void inputMethodEvent(QInputMethodEvent event)
inputMethodQuery()
, and sceneEvent()
.
inputMethodEvent
in interface QGraphicsItemInterface
public java.lang.Object inputMethodQuery(Qt.InputMethodQuery query)
inputMethodEvent()
.
inputMethodQuery
in interface QGraphicsItemInterface
public boolean isObscuredBy(QGraphicsItemInterface item)
The base implementation maps item's opaqueArea()
to this item's coordinate system, and then checks if this item's boundingRect()
is fully contained within the mapped shape.
You can reimplement this function to provide a custom algorithm for determining whether this item is obscured by item.
opaqueArea()
, and isObscured()
.
isObscuredBy
in interface QGraphicsItemInterface
public java.lang.Object itemChange(QGraphicsItem.GraphicsItemChange change, java.lang.Object value)
QGraphicsItem
to notify custom items that some part of the item's state changes. By reimplementing this function, your can react to a change, and in some cases, (depending on change,) adjustments can be made. change is the parameter of the item that is changing. value is the new value; the type of the value depends on change.
Example:
public Object itemChange(GraphicsItemChange change, Object value) { if (change == GraphicsItemChange.ItemPositionChange && scene() != null) { // value is the new position. QPointF newPos = (QPointF)value; QRectF rect = scene().sceneRect(); if (!rect.contains(newPos)) { // Keep the item inside the scene rect. newPos.setX(Math.min(rect.right(), Math.max(newPos.x(), rect.left()))); newPos.setY(Math.min(rect.bottom(), Math.max(newPos.y(), rect.top()))); return newPos; } } return super.itemChange(change, value); }The default implementation does nothing, and returns value.
Note: Certain QGraphicsItem
functions cannot be called in a reimplementation of this function; see the GraphicsItemChange
documentation for details.
GraphicsItemChange
.
itemChange
in interface QGraphicsItemInterface
public void keyPressEvent(QKeyEvent event)
Note that key events are only received for items that set the ItemIsFocusable
flag, and that have keyboard input focus.
keyReleaseEvent()
, setFocus()
, QGraphicsScene::setFocusItem()
, and sceneEvent()
.
keyPressEvent
in interface QGraphicsItemInterface
public void keyReleaseEvent(QKeyEvent event)
Note that key events are only received for items that set the ItemIsFocusable
flag, and that have keyboard input focus.
keyPressEvent()
, setFocus()
, QGraphicsScene::setFocusItem()
, and sceneEvent()
.
keyReleaseEvent
in interface QGraphicsItemInterface
public void mouseDoubleClickEvent(QGraphicsSceneMouseEvent event)
When doubleclicking an item, the item will first receive a mouse press event, followed by a release event (i.e., a click), then a doubleclick event, and finally a release event.
Calling QEvent::ignore()
or QEvent::accept()
on event has no effect.
The default implementation calls mousePressEvent()
. If you want to keep the base implementation when reimplementing this function, call QGraphicsItem::mouseDoubleClickEvent()
in your reimplementation.
Note that an item will not receive double click events if it is neither selectable
nor movable
(single mouse clicks are ignored in this case, and that stops the generation of double clicks).
mousePressEvent()
, mouseMoveEvent()
, mouseReleaseEvent()
, and sceneEvent()
.
mouseDoubleClickEvent
in interface QGraphicsItemInterface
public void mouseMoveEvent(QGraphicsSceneMouseEvent event)
Calling QEvent::ignore()
or QEvent::accept()
on event has no effect.
The default implementation handles basic item interaction, such as selection and moving. If you want to keep the base implementation when reimplementing this function, call QGraphicsItem::mouseMoveEvent()
in your reimplementation.
Please note that mousePressEvent()
decides which graphics item it is that receives mouse events. See the mousePressEvent()
description for details.
mousePressEvent()
, mouseReleaseEvent()
, mouseDoubleClickEvent()
, and sceneEvent()
.
mouseMoveEvent
in interface QGraphicsItemInterface
public void mousePressEvent(QGraphicsSceneMouseEvent event)
setAcceptedMouseButtons()
. The mouse press event decides which item should become the mouse grabber (see QGraphicsScene::mouseGrabberItem()
). If you do not reimplement this function, the press event will propagate to any topmost item beneath this item, and no other mouse events will be delivered to this item.
If you do reimplement this function, event will by default be accepted (see QEvent::accept()
), and this item is then the mouse grabber. This allows the item to receive future move, release and doubleclick events. If you call QEvent::ignore()
on event, this item will lose the mouse grab, and event will propagate to any topmost item beneath. No further mouse events will be delivered to this item unless a new mouse press event is received.
The default implementation handles basic item interaction, such as selection and moving. If you want to keep the base implementation when reimplementing this function, call QGraphicsItem::mousePressEvent()
in your reimplementation.
The event is QEvent::ignore()
d for items that are neither movable
nor selectable
.
mouseMoveEvent()
, mouseReleaseEvent()
, mouseDoubleClickEvent()
, and sceneEvent()
.
mousePressEvent
in interface QGraphicsItemInterface
public void mouseReleaseEvent(QGraphicsSceneMouseEvent event)
Calling QEvent::ignore()
or QEvent::accept()
on event has no effect.
The default implementation handles basic item interaction, such as selection and moving. If you want to keep the base implementation when reimplementing this function, call QGraphicsItem::mouseReleaseEvent()
in your reimplementation.
Please note that mousePressEvent()
decides which graphics item it is that receives mouse events. See the mousePressEvent()
description for details.
mousePressEvent()
, mouseMoveEvent()
, mouseDoubleClickEvent()
, and sceneEvent()
.
mouseReleaseEvent
in interface QGraphicsItemInterface
public QPainterPath opaqueArea()
This function is used by isObscuredBy()
, which is called by underlying items to determine if they are obscured by this item.
The default implementation returns an empty QPainterPath
, indicating that this item is completely transparent and does not obscure any other items.
isObscuredBy()
, isObscured()
, and shape()
.
opaqueArea
in interface QGraphicsItemInterface
public void paint(QPainter painter, QStyleOptionGraphicsItem option, QWidget widget)
QGraphicsView
, paints the contents of an item in local coordinates. Reimplement this function in a QGraphicsItem
subclass to provide the item's painting implementation, using painter. The option parameter provides style options for the item, such as its state, exposed area and its level-of-detail hints. The widget argument is optional. If provided, it points to the widget that is being painted on; otherwise, it is 0. For cached painting, widget is always 0.
public class RoundRectItem extends QGraphicsItem { // ... public void paint(QPainter painter, QStyleOptionGraphicsItem option, QWidget widget) { painter.drawRoundRect(-10, -10, 20, 20, 5, 5); } // ... }The painter's pen is 0-width by default, and its pen is initialized to the
QPalette::Text
brush from the paint device's palette. The brush is initialized to QPalette::Window
. Make sure to constrain all painting inside the boundaries of boundingRect()
to avoid rendering artifacts (as QGraphicsView
does not clip the painter for you). In particular, when QPainter
renders the outline of a shape using an assigned QPen
, half of the outline will be drawn outside, and half inside, the shape you're rendering (e.g., with a pen width of 2 units, you must draw outlines 1 unit inside boundingRect()
). QGraphicsItem
does not support use of cosmetic pens with a non-zero width.
All painting is done in local coordinates.
setCacheMode()
, QPen::width()
, and Item Coordinates.
paint
in interface QGraphicsItemInterface
public boolean sceneEvent(QEvent event)
contextMenuEvent()
, focusInEvent()
, focusOutEvent()
, hoverEnterEvent()
, hoverMoveEvent()
, hoverLeaveEvent()
, keyPressEvent()
, keyReleaseEvent()
, mousePressEvent()
, mouseReleaseEvent()
, mouseMoveEvent()
, and mouseDoubleClickEvent()
. Returns true if the event was recognized and handled; otherwise, (e.g., if the event type was not recognized,) false is returned.
event is the intercepted event.
sceneEvent
in interface QGraphicsItemInterface
public boolean sceneEventFilter(QGraphicsItemInterface watched, QEvent event)
Reimplementing this function in a subclass makes it possible for the item to be used as an event filter for other items, intercepting all the events send to those items before they are able to respond.
Reimplementations must return true to prevent further processing of a given event, ensuring that it will not be delivered to the watched item, or return false to indicate that the event should be propagated further by the event system.
installSceneEventFilter()
.
sceneEventFilter
in interface QGraphicsItemInterface
public QPainterPath shape()
QPainterPath
in local coordinates. The shape is used for many things, including collision detection, hit tests, and for the QGraphicsScene::items()
functions. The default implementation calls boundingRect()
to return a simple rectangular shape, but subclasses can reimplement this function to return a more accurate shape for non-rectangular items. For example, a round item may choose to return an elliptic shape for better collision detection. For example:
public class RoundItem extends QGraphicsItem { // ... public QPainterPath shape() { QPainterPath path = new QPainterPath(); path.addEllipse(boundingRect()); return path; } // ... }The outline of a shape can vary depending on the width and style of the pen used when drawing. If you want to include this outline in the item's shape, you can create a shape from the stroke using
QPainterPathStroker
. This function is called by the default implementations of contains()
and collidesWithPath()
.
boundingRect()
, contains()
, prepareGeometryChange()
, and QPainterPathStroker
.
shape
in interface QGraphicsItemInterface
public int type()
The default implementation (in QGraphicsItem
) returns UserType.
To enable use of qgraphicsitem_cast() with a custom item, reimplement this function and declare a Type enum value equal to your custom item's type. Custom items must return a value larger than or equal to UserType (65536).
For example:Error parsing snippet.
type
in interface QGraphicsItemInterface
public void wheelEvent(QGraphicsSceneWheelEvent event)
If you ignore the event, (i.e., by calling QEvent::ignore()
,) it will propagate to any item beneath this item. If no items accept the event, it will be ignored by the scene, and propagate to the view (e.g., the view's vertical scroll bar).
The default implementation ignores the event.
sceneEvent()
.
wheelEvent
in interface QGraphicsItemInterface
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |