|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.gui.QGraphicsScene
public class QGraphicsScene
The QGraphicsScene
class provides a surface for managing a large number of 2D graphical items. The class serves as a container for QGraphicsItems
. It is used together with QGraphicsView
for visualizing graphical items, such as lines, rectangles, text, or even custom items, on a 2D surface. QGraphicsScene
is part of The Graphics View Framework.
QGraphicsScene
also provides functionality that lets you efficiently determine both the location of items, and for determining what items are visible within an arbitrary area on the scene. With the QGraphicsView
widget, you can either visualize the whole scene, or zoom in and view only parts of the scene.
Example:
QGraphicsScene scene = new QGraphicsScene(); scene.addText("Hello, world!"); QGraphicsView view = new QGraphicsView(scene); view.show();Note that
QGraphicsScene
has no visual appearance of its own; it only manages the items. You need to create a QGraphicsView
widget to visualize the scene. To add items to a scene, you start off by constructing a QGraphicsScene
object. Then, you have two options: either add your existing QGraphicsItem
objects by calling addItem()
, or you can call one of the convenience functions addEllipse()
, addLine()
, addPath()
, addPixmap()
, addPolygon()
, addRect()
, or addText()
, which all return a pointer to the newly added item. The dimensions of the items added with these functions are relative to the item's coordinate system, and the items position is initialized to (0, 0) in the scene.
You can then visualize the scene using QGraphicsView
. When the scene changes, (e.g., when an item moves or is transformed) QGraphicsScene
emits the changed()
signal. To remove an item, call removeItem()
.
QGraphicsScene
uses an indexing algorithm to manage the location of items efficiently. By default, a BSP (Binary Space Partitioning) tree is used; an algorithm suitable for large scenes where most items remain static (i.e., do not move around). You can choose to disable this index by calling setItemIndexMethod()
. For more information about the available indexing algorithms, see the itemIndexMethod
property.
The scene's bounding rect is set by calling setSceneRect()
. Items can be placed at any position on the scene, and the size of the scene is by default unlimited. The scene rect is used only for internal bookkeeping, maintaining the scene's item index. If the scene rect is unset, QGraphicsScene
will use the bounding area of all items, as returned by itemsBoundingRect()
, as the scene rect. However, itemsBoundingRect()
is a relatively time consuming function, as it operates by collecting positional information for every item on the scene. Because of this, you should always set the scene rect when operating on large scenes.
One of QGraphicsScene
's greatest strengths is its ability to efficiently determine the location of items. Even with millions of items on the scene, the items()
functions can determine the location of an item within few milliseconds. There are several overloads to items()
: one that finds items at a certain position, one that finds items inside or intersecting with a polygon or a rectangle, and more. The list of returned items is sorted by stacking order, with the topmost item being the first item in the list. For convenience, there is also an itemAt()
function that returns the topmost item at a given position.
QGraphicsScene
maintains selection information for the scene. To select items, call setSelectionArea()
, and to clear the current selection, call clearSelection()
. Call selectedItems()
to get the list of all selected items.Event Handling and Propagation
Another responsibility that QGraphicsScene
has, is to propagate events from QGraphicsView
. To send an event to a scene, you construct an event that inherits QEvent
, and then send it using, for example, QApplication::sendEvent()
. event()
is responsible for dispatching the event to the individual items. Some common events are handled by convenience event handlers. For example, key press events are handled by keyPressEvent()
, and mouse press events are handled by mousePressEvent()
.
Key events are delivered to the focus item. To set the focus item, you can either call setFocusItem()
, passing an item that accepts focus, or the item itself can call QGraphicsItem::setFocus()
. Call focusItem()
to get the current focus item. For compatibility with widgets, the scene also maintains its own focus information. By default, the scene does not have focus, and all key events are discarded. If setFocus()
is called, or if an item on the scene gains focus, the scene automatically gains focus. If the scene has focus, hasFocus()
will return true, and key events will be forwarded to the focus item, if any. If the scene loses focus, (i.e., someone calls clearFocus()
,) while an item has focus, the scene will maintain its item focus information, and once the scene regains focus, it will make sure the last focus item regains focus.
For mouse-over effects, QGraphicsScene
dispatches hover events. If an item accepts hover events (see QGraphicsItem::acceptHoverEvents()
), it will receive a GraphicsSceneHoverEnter
event when the mouse enters its area. As the mouse continues moving inside the item's area, QGraphicsScene
will send it GraphicsSceneHoverMove
events. When the mouse leaves the item's area, the item will receive a GraphicsSceneHoverLeave
event.
All mouse events are delivered to the current mouse grabber item. An item becomes the scene's mouse grabber if it accepts mouse events (see QGraphicsItem::acceptedMouseButtons()
) and it receives a mouse press. It stays the mouse grabber until it receives a mouse release when no other mouse buttons are pressed. You can call mouseGrabberItem()
to determine what item is currently grabbing the mouse.
QGraphicsItem
, and QGraphicsView
.
Nested Class Summary | |
---|---|
static class |
QGraphicsScene.ItemIndexMethod
This enum describes the indexing algorithms QGraphicsScene provides for managing positional information about items on the scene. |
static class |
QGraphicsScene.SceneLayer
This enum describes the rendering layers in a QGraphicsScene . |
static class |
QGraphicsScene.SceneLayers
This is a flags class for com.trolltech.qt.gui.QGraphicsScene.SceneLayer |
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Field Summary | |
---|---|
QSignalEmitter.Signal1 |
changed
This signal is emitted by QGraphicsScene when control reaches the event loop, if the scene content changes. |
QSignalEmitter.Signal1 |
sceneRectChanged
This signal is emitted by QGraphicsScene whenever the scene rect changes. |
QSignalEmitter.Signal0 |
selectionChanged
This signal is emitted by QGraphicsScene whenever the selection changes. |
Constructor Summary | |
---|---|
QGraphicsScene()
Constructs a QGraphicsScene object. |
|
QGraphicsScene(double x,
double y,
double width,
double height)
Constructs a QGraphicsScene object, using the rectangle specified by (x, y), and the given width and height for its scene rectangle. |
|
QGraphicsScene(double x,
double y,
double width,
double height,
QObject parent)
Constructs a QGraphicsScene object, using the rectangle specified by (x, y), and the given width and height for its scene rectangle. |
|
QGraphicsScene(QObject parent)
Constructs a QGraphicsScene object. |
|
QGraphicsScene(QRectF sceneRect)
Constructs a QGraphicsScene object, using sceneRect for its scene rectangle. |
|
QGraphicsScene(QRectF sceneRect,
QObject parent)
Constructs a QGraphicsScene object, using sceneRect for its scene rectangle. |
Method Summary | |
---|---|
QGraphicsWidget |
activeWindow()
Returns the current active window, or 0 if there is no window is currently active. |
QGraphicsEllipseItem |
addEllipse(double x,
double y,
double w,
double h)
Equivalent to addEllipse(x, y, w, h, null, null) |
QGraphicsEllipseItem |
addEllipse(double x,
double y,
double w,
double h,
QPen pen)
Equivalent to addEllipse(x, y, w, h, pen, null) |
QGraphicsEllipseItem |
addEllipse(double x,
double y,
double w,
double h,
QPen pen,
QBrush brush)
Creates and adds an ellipse item to the scene, and returns the item reference. |
QGraphicsEllipseItem |
addEllipse(QRectF rect)
Equivalent to addEllipse(rect, null, null) |
QGraphicsEllipseItem |
addEllipse(QRectF rect,
QPen pen)
Equivalent to addEllipse(rect, pen, null) |
QGraphicsEllipseItem |
addEllipse(QRectF rect,
QPen pen,
QBrush brush)
Creates and adds an ellipse item to the scene, and returns the item reference. |
void |
addItem(QGraphicsItemInterface item)
Adds or moves the item item and all its childen to the scene. |
QGraphicsLineItem |
addLine(double x1,
double y1,
double x2,
double y2)
Equivalent to addLine(x1, y1, x2, y2, null) |
QGraphicsLineItem |
addLine(double x1,
double y1,
double x2,
double y2,
QPen pen)
Creates and adds a line item to the scene, and returns the item reference. |
QGraphicsLineItem |
addLine(QLineF line)
Equivalent to addLine(line, null) |
QGraphicsLineItem |
addLine(QLineF line,
QPen pen)
Creates and adds a line item to the scene, and returns the item reference. |
QGraphicsPathItem |
addPath(QPainterPath path)
Equivalent to addPath(path, null, null) |
QGraphicsPathItem |
addPath(QPainterPath path,
QPen pen)
Equivalent to addPath(path, pen, null) |
QGraphicsPathItem |
addPath(QPainterPath path,
QPen pen,
QBrush brush)
Creates and adds a path item to the scene, and returns the item reference. |
QGraphicsPixmapItem |
addPixmap(QPixmap pixmap)
Creates and adds a pixmap item to the scene, and returns the item reference. |
QGraphicsPolygonItem |
addPolygon(QPolygonF polygon)
Equivalent to addPolygon(polygon, null, null) |
QGraphicsPolygonItem |
addPolygon(QPolygonF polygon,
QPen pen)
Equivalent to addPolygon(polygon, pen, null) |
QGraphicsPolygonItem |
addPolygon(QPolygonF polygon,
QPen pen,
QBrush brush)
Creates and adds a polygon item to the scene, and returns the item reference. |
QGraphicsRectItem |
addRect(double x,
double y,
double w,
double h)
Equivalent to addRect(x, y, w, h, null, null) |
QGraphicsRectItem |
addRect(double x,
double y,
double w,
double h,
QPen pen)
Equivalent to addRect(x, y, w, h, pen, null) |
QGraphicsRectItem |
addRect(double x,
double y,
double w,
double h,
QPen pen,
QBrush brush)
Creates and adds a rectangle item to the scene, and returns the item reference. |
QGraphicsRectItem |
addRect(QRectF rect)
Equivalent to addRect(rect, null, null) |
QGraphicsRectItem |
addRect(QRectF rect,
QPen pen)
Equivalent to addRect(rect, pen, null) |
QGraphicsRectItem |
addRect(QRectF rect,
QPen pen,
QBrush brush)
Creates and adds a rectangle item to the scene, and returns the item reference. |
QGraphicsSimpleTextItem |
addSimpleText(java.lang.String text)
Equivalent to addSimpleText(text, null) |
QGraphicsSimpleTextItem |
addSimpleText(java.lang.String text,
QFont font)
Creates and adds a QGraphicsSimpleTextItem to the scene, and returns the item reference. |
QGraphicsTextItem |
addText(java.lang.String text)
Equivalent to addText(text, null) |
QGraphicsTextItem |
addText(java.lang.String text,
QFont font)
Creates and adds a text item to the scene, and returns the item reference. |
QGraphicsProxyWidget |
addWidget(QWidget widget)
Creates a new QGraphicsProxyWidget for widget, adds it to the scene, and returns a pointer to the proxy. |
QGraphicsProxyWidget |
addWidget(QWidget widget,
Qt.WindowFlags wFlags)
Creates a new QGraphicsProxyWidget for widget, adds it to the scene, and returns a pointer to the proxy. |
QGraphicsProxyWidget |
addWidget(QWidget widget,
Qt.WindowType[] wFlags)
Creates a new QGraphicsProxyWidget for widget, adds it to the scene, and returns a pointer to the proxy. |
void |
advance()
This slot advances the scene by one step, by calling QGraphicsItem::advance() for all items on the scene. |
QBrush |
backgroundBrush()
This property holds the background brush of the scene. |
int |
bspTreeDepth()
This property holds the depth of QGraphicsScene 's BSP index tree. |
void |
clear()
Removes and deletes all items from the scene, but otherwise leaves the state of the scene unchanged. |
void |
clearFocus()
Clears focus from the scene. |
void |
clearSelection()
Clears the current selection. |
java.util.List |
collidingItems(QGraphicsItemInterface item)
Returns a list of all items that collide with item. |
java.util.List |
collidingItems(QGraphicsItemInterface item,
Qt.ItemSelectionMode mode)
Returns a list of all items that collide with item. |
protected void |
contextMenuEvent(QGraphicsSceneContextMenuEvent event)
This event handler, for event contextMenuEvent, can be reimplemented in a subclass to receive context menu events. |
QGraphicsItemGroup |
createItemGroup(java.util.List items)
Groups all items in items into a new QGraphicsItemGroup , and returns a pointer to the group. |
void |
destroyItemGroup(QGraphicsItemGroup group)
Reparents all items in group to group's parent item, then removes group from the scene, and finally deletes it. |
protected void |
dragEnterEvent(QGraphicsSceneDragDropEvent event)
This event handler, for event event, can be reimplemented in a subclass to receive drag enter events for the scene. |
protected void |
dragLeaveEvent(QGraphicsSceneDragDropEvent event)
This event handler, for event event, can be reimplemented in a subclass to receive drag leave events for the scene. |
protected void |
dragMoveEvent(QGraphicsSceneDragDropEvent event)
This event handler, for event event, can be reimplemented in a subclass to receive drag move events for the scene. |
protected void |
drawBackground(QPainter painter,
QRectF rect)
Draws the background of the scene using painter, before any items and the foreground are drawn. |
protected void |
drawForeground(QPainter painter,
QRectF rect)
Draws the foreground of the scene using painter, after the background and all items have been drawn. |
protected void |
drawItems(QPainter painter,
QGraphicsItemInterface[] items,
QStyleOptionGraphicsItem[] options)
|
protected void |
drawItems(QPainter painter,
QGraphicsItemInterface[] items,
QStyleOptionGraphicsItem[] options,
QWidget widget)
|
protected void |
dropEvent(QGraphicsSceneDragDropEvent event)
This event handler, for event event, can be reimplemented in a subclass to receive drop events for the scene. |
protected void |
focusInEvent(QFocusEvent event)
This event handler, for event focusEvent, can be reimplemented in a subclass to receive focus in events. |
QGraphicsItemInterface |
focusItem()
Returns the scene's current focus item, or 0 if no item currently has focus. |
protected boolean |
focusNextPrevChild(boolean next)
Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget, or false if it cannot. |
protected void |
focusOutEvent(QFocusEvent event)
This event handler, for event focusEvent, can be reimplemented in a subclass to receive focus out events. |
QFont |
font()
This property holds the scene's default font. |
QBrush |
foregroundBrush()
This property holds the foreground brush of the scene. |
static QGraphicsScene |
fromNativePointer(QNativePointer nativePointer)
|
boolean |
hasFocus()
Returns true if the scene has focus; otherwise returns false. |
double |
height()
This convenience function is equivalent to calling sceneRect().height(). |
protected void |
helpEvent(QGraphicsSceneHelpEvent event)
This event handler, for event helpEvent, can be reimplemented in a subclass to receive help events. |
protected void |
inputMethodEvent(QInputMethodEvent event)
This event handler, for event event, can be reimplemented in a subclass to receive input method events for the scene. |
java.lang.Object |
inputMethodQuery(Qt.InputMethodQuery query)
This method is used by input methods to query a set of properties of the scene to be able to support complex input method operations as support for surrounding text and reconversions. |
void |
invalidate()
Invalidates and schedules a redraw of the layers in rect on the scene. |
void |
invalidate(double x,
double y,
double w,
double h)
This convenience function is equivalent to calling invalidate( QRectF (x, y, w, h), layers); |
void |
invalidate(double x,
double y,
double w,
double h,
QGraphicsScene.SceneLayer[] layers)
This convenience function is equivalent to calling invalidate( QRectF (x, y, w, h), layers); |
void |
invalidate(double x,
double y,
double w,
double h,
QGraphicsScene.SceneLayers layers)
This convenience function is equivalent to calling invalidate( QRectF (x, y, w, h), layers); |
void |
invalidate(QRectF rect)
Invalidates and schedules a redraw of the layers in rect on the scene. |
void |
invalidate(QRectF rect,
QGraphicsScene.SceneLayer[] layers)
Invalidates and schedules a redraw of the layers in rect on the scene. |
void |
invalidate(QRectF rect,
QGraphicsScene.SceneLayers layers)
Invalidates and schedules a redraw of the layers in rect on the scene. |
QGraphicsItemInterface |
itemAt(double x,
double y)
Returns the topmost item at the position specified by (x, y), or 0 if there are no items at this position. |
QGraphicsItemInterface |
itemAt(QPointF pos)
Returns the topmost visible item at the specified position, or 0 if there are no items at this position. |
QGraphicsScene.ItemIndexMethod |
itemIndexMethod()
This property holds the item indexing method. |
java.util.List |
items()
Returns a list of all items on the scene, in no particular order. |
java.util.List |
items(double x,
double y,
double w,
double h)
This convenience function is equivalent to calling items(QRectF(x, y, w, h). |
java.util.List |
items(double x,
double y,
double w,
double h,
Qt.ItemSelectionMode mode)
This convenience function is equivalent to calling items( QRectF (x, y, w, h), mode). |
java.util.List |
items(QPainterPath path)
Returns all visible items that are either inside or intersect with the path path. |
java.util.List |
items(QPainterPath path,
Qt.ItemSelectionMode mode)
Returns all visible items that, depending on path, are either inside or intersect with the path path. |
java.util.List |
items(QPointF pos)
Returns all visible items at position pos in the scene. |
java.util.List |
items(QPolygonF polygon)
Returns all visible items that are either inside or intersect with the polygon polygon. |
java.util.List |
items(QPolygonF polygon,
Qt.ItemSelectionMode mode)
Returns all visible items that, depending on mode, are either inside or intersect with the polygon polygon. |
java.util.List |
items(QRectF rect)
Returns all visible items that are either inside or intersect with the specified rectangle. |
java.util.List |
items(QRectF rect,
Qt.ItemSelectionMode mode)
Returns all visible items that, depending on mode, are either inside or intersect with the specified rectangle. |
QRectF |
itemsBoundingRect()
Calculates and returns the bounding rect of all items on the scene. |
protected void |
keyPressEvent(QKeyEvent event)
This event handler, for event keyEvent, can be reimplemented in a subclass to receive keypress events. |
protected void |
keyReleaseEvent(QKeyEvent event)
This event handler, for event keyEvent, can be reimplemented in a subclass to receive key release events. |
protected void |
mouseDoubleClickEvent(QGraphicsSceneMouseEvent event)
This event handler, for event mouseEvent, can be reimplemented in a subclass to receive mouse doubleclick events for the scene. |
QGraphicsItemInterface |
mouseGrabberItem()
Returns the current mouse grabber item, or 0 if no item is currently grabbing the mouse. |
protected void |
mouseMoveEvent(QGraphicsSceneMouseEvent event)
This event handler, for event mouseEvent, can be reimplemented in a subclass to receive mouse move events for the scene. |
protected void |
mousePressEvent(QGraphicsSceneMouseEvent event)
This event handler, for event mouseEvent, can be reimplemented in a subclass to receive mouse press events for the scene. |
protected void |
mouseReleaseEvent(QGraphicsSceneMouseEvent event)
This event handler, for event mouseEvent, can be reimplemented in a subclass to receive mouse release events for the scene. |
QPalette |
palette()
This property holds the scene's default palette. |
void |
removeItem(QGraphicsItemInterface item)
Removes the item item and all its children from the scene. |
void |
render(QPainter painter)
Renders the source rect from scene into target, using painter. |
void |
render(QPainter painter,
QRectF target)
Renders the source rect from scene into target, using painter. |
void |
render(QPainter painter,
QRectF target,
QRectF source)
Renders the source rect from scene into target, using painter. |
void |
render(QPainter painter,
QRectF target,
QRectF source,
Qt.AspectRatioMode aspectRatioMode)
Renders the source rect from scene into target, using painter. |
QRectF |
sceneRect()
This property holds the scene rectangle; the bounding rectangle of the scene. |
java.util.List |
selectedItems()
Returns a list of all currently selected items. |
QPainterPath |
selectionArea()
Returns the selection area that was previously set with setSelectionArea() , or an empty QPainterPath if no selection area has been set. |
void |
setActiveWindow(QGraphicsWidget widget)
Activates widget, which must be a widget in this scene. |
void |
setBackgroundBrush(QBrush brush)
This property holds the background brush of the scene. |
void |
setBspTreeDepth(int depth)
This property holds the depth of QGraphicsScene 's BSP index tree. |
void |
setFocus()
Sets focus on the scene by sending a QFocusEvent to the scene, passing focusReason as the reason. |
void |
setFocus(Qt.FocusReason focusReason)
Sets focus on the scene by sending a QFocusEvent to the scene, passing focusReason as the reason. |
void |
setFocusItem(QGraphicsItemInterface item)
Sets the scene's focus item to item, with the focus reason focusReason, after removing focus from any previous item that may have had focus. |
void |
setFocusItem(QGraphicsItemInterface item,
Qt.FocusReason focusReason)
Sets the scene's focus item to item, with the focus reason focusReason, after removing focus from any previous item that may have had focus. |
void |
setFont(QFont font)
This property holds the scene's default font. |
void |
setForegroundBrush(QBrush brush)
This property holds the foreground brush of the scene. |
void |
setItemIndexMethod(QGraphicsScene.ItemIndexMethod method)
This property holds the item indexing method. |
void |
setPalette(QPalette palette)
This property holds the scene's default palette. |
void |
setSceneRect(double x,
double y,
double w,
double h)
This property holds the scene rectangle; the bounding rectangle of the scene. |
void |
setSceneRect(QRectF rect)
This property holds the scene rectangle; the bounding rectangle of the scene. |
void |
setSelectionArea(QPainterPath path)
Sets the selection area to path. |
void |
setSelectionArea(QPainterPath path,
Qt.ItemSelectionMode arg__2)
Sets the selection area to path using mode to determine if items are included in the selection area. |
void |
setStyle(QStyle style)
Sets or replaces the style of the scene to style, and reparents the style to this scene. |
QStyle |
style()
Returns the scene's style, or the same as QApplication::style() if the scene has not been explicitly assigned a style. |
void |
update()
Schedules a redraw of the area rect on the scene. |
void |
update(double x,
double y,
double w,
double h)
This function is equivalent to calling update( QRectF (x, y, w, h)); |
void |
update(QRectF rect)
Schedules a redraw of the area rect on the scene. |
java.util.List |
views()
Returns a list of all the views that display this scene. |
protected void |
wheelEvent(QGraphicsSceneWheelEvent event)
This event handler, for event wheelEvent, can be reimplemented in a subclass to receive mouse wheel events for the scene. |
double |
width()
This convenience function is equivalent to calling sceneRect() .width() . |
Methods inherited from class com.trolltech.qt.core.QObject |
---|
childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty |
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 java.lang.Object |
---|
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Field Detail |
---|
public final QSignalEmitter.Signal1 changed
QGraphicsScene
when control reaches the event loop, if the scene content changes. The region parameter contains a list of scene rectangles that indicate the area that has been changed. QGraphicsView::updateScene()
.
public final QSignalEmitter.Signal1 sceneRectChanged
QGraphicsScene
whenever the scene rect changes. The rect parameter is the new scene rectangle. QGraphicsView::updateSceneRect()
.
public final QSignalEmitter.Signal0 selectionChanged
QGraphicsScene
whenever the selection changes. You can call selectedItems()
to get the new list of selected items. The selection changes whenever an item is selected or unselected, a selection area is set, cleared or otherwise changed, if a preselected item is added to the scene, or if a selected item is removed from the scene.
QGraphicsScene
emits this signal only once for group selection operations. For example, if you set a selection area, select or unselect a QGraphicsItemGroup
, or if you add or remove from the scene a parent item that contains several selected items, selectionChanged()
is emitted only once after the operation has completed (instead of once for each item).
setSelectionArea()
, selectedItems()
, and QGraphicsItem::setSelected()
.
Constructor Detail |
---|
public QGraphicsScene()
QGraphicsScene
object. The parent parameter is passed to QObject
's constructor.
public QGraphicsScene(QObject parent)
QGraphicsScene
object. The parent parameter is passed to QObject
's constructor.
public QGraphicsScene(QRectF sceneRect)
QGraphicsScene
object, using sceneRect for its scene rectangle. The parent parameter is passed to QObject
's constructor. sceneRect
.
public QGraphicsScene(QRectF sceneRect, QObject parent)
QGraphicsScene
object, using sceneRect for its scene rectangle. The parent parameter is passed to QObject
's constructor. sceneRect
.
public QGraphicsScene(double x, double y, double width, double height)
QGraphicsScene
object, using the rectangle specified by (x, y), and the given width and height for its scene rectangle. The parent parameter is passed to QObject
's constructor. sceneRect
.
public QGraphicsScene(double x, double y, double width, double height, QObject parent)
QGraphicsScene
object, using the rectangle specified by (x, y), and the given width and height for its scene rectangle. The parent parameter is passed to QObject
's constructor. sceneRect
.
Method Detail |
---|
public final QGraphicsWidget activeWindow()
QGraphicsScene::setActiveWindow()
.
public final void addItem(QGraphicsItemInterface item)
If the item is visible (i.e., QGraphicsItem::isVisible()
returns true), QGraphicsScene
will emit changed()
once control goes back to the event loop.
If the item is already in a different scene, it will first be removed from its old scene, and then added to this scene as a top-level.
QGraphicsScene
will send ItemSceneChange
notifications to item while it is added to the scene. If item does not currently belong to a scene, only one notification is sent. If it does belong to scene already (i.e., it is moved to this scene), QGraphicsScene
will send an addition notification as the item is removed from its previous scene.
removeItem()
, addEllipse()
, addLine()
, addPath()
, addPixmap()
, addRect()
, addText()
, and addWidget()
.
public final QGraphicsProxyWidget addWidget(QWidget widget, Qt.WindowType[] wFlags)
QGraphicsProxyWidget
for widget, adds it to the scene, and returns a pointer to the proxy. wFlags set the default window flags for the embedding proxy widget. The item's position is initialized to (0, 0).
If the item is visible (i.e., QGraphicsItem::isVisible()
returns true), QGraphicsScene
will emit changed()
once control goes back to the event loop.
addEllipse()
, addLine()
, addPixmap()
, addPixmap()
, addRect()
, addText()
, addSimpleText()
, and addItem()
.
public final QGraphicsProxyWidget addWidget(QWidget widget)
QGraphicsProxyWidget
for widget, adds it to the scene, and returns a pointer to the proxy. wFlags set the default window flags for the embedding proxy widget. The item's position is initialized to (0, 0).
If the item is visible (i.e., QGraphicsItem::isVisible()
returns true), QGraphicsScene
will emit changed()
once control goes back to the event loop.
addEllipse()
, addLine()
, addPixmap()
, addPixmap()
, addRect()
, addText()
, addSimpleText()
, and addItem()
.
public final QGraphicsProxyWidget addWidget(QWidget widget, Qt.WindowFlags wFlags)
QGraphicsProxyWidget
for widget, adds it to the scene, and returns a pointer to the proxy. wFlags set the default window flags for the embedding proxy widget. The item's position is initialized to (0, 0).
If the item is visible (i.e., QGraphicsItem::isVisible()
returns true), QGraphicsScene
will emit changed()
once control goes back to the event loop.
addEllipse()
, addLine()
, addPixmap()
, addPixmap()
, addRect()
, addText()
, addSimpleText()
, and addItem()
.
public final void advance()
QGraphicsItem::advance()
for all items on the scene. This is done in two phases: in the first phase, all items are notified that the scene is about to change, and in the second phase all items are notified that they can move. In the first phase, QGraphicsItem::advance()
is called passing a value of 0 as an argument, and 1 is passed in the second phase. QGraphicsItem::advance()
, QGraphicsItemAnimation
, and QTimeLine
.
public final QBrush backgroundBrush()
Qt::NoBrush
. The background is drawn before (behind) the items. Example:
QGraphicsScene scene = new QGraphicsScene(); QGraphicsView view = new QGraphicsView(scene); view.show(); // a blue background scene.setBackgroundBrush(new QBrush(QColor.blue)); // a gradient background QRadialGradient gradient = new QRadialGradient(0, 0, 10); gradient.setSpread(QGradient.Spread.RepeatSpread); scene.setBackgroundBrush(new QBrush(gradient));
QGraphicsScene::render()
calls drawBackground()
to draw the scene background. For more detailed control over how the background is drawn, you can reimplement drawBackground()
in a subclass of QGraphicsScene
.
public final int bspTreeDepth()
QGraphicsScene
's BSP index tree. This property has no effect when NoIndex
is used. This value determines the depth of QGraphicsScene
's BSP tree. The depth directly affects QGraphicsScene
's performance and memory usage; the latter growing exponentially with the depth of the tree. With an optimal tree depth, QGraphicsScene
can instantly determine the locality of items, even for scenes with thousands or millions of items. This also greatly improves rendering performance.
By default, the value is 0, in which case Qt will guess a reasonable default depth based on the size, location and number of items in the scene. If these parameters change frequently, however, you may experience slowdowns as QGraphicsScene
retunes the depth internally. You can avoid potential slowdowns by fixating the tree depth through setting this property.
The depth of the tree and the size of the scene rectangle decide the granularity of the scene's partitioning. The size of each scene segment is determined by the following algorithm:
QSizeF segmentSize = sceneRect().size().divide(java.lang.Math.pow(2, depth - 1));The BSP tree has an optimal size when each segment contains between 0 and 10 items.
itemIndexMethod
.
public final void clear()
addItem()
.
public final void clearFocus()
A scene that does not have focus ignores key events.
hasFocus()
, setFocus()
, and setFocusItem()
.
public final void clearSelection()
setSelectionArea()
, and selectedItems()
.
public final java.util.List collidingItems(QGraphicsItemInterface item)
The items are returned in descending Z order (i.e., the first item in the list is the top-most item, and the last item is the bottom-most item).
public final java.util.List collidingItems(QGraphicsItemInterface item, Qt.ItemSelectionMode mode)
QGraphicsItem::collidesWithItem()
; the collision detection is determined by mode. By default, all items whose shape intersects item or is contained inside item's shape are returned. The items are returned in descending Z order (i.e., the first item in the list is the top-most item, and the last item is the bottom-most item).
items()
, itemAt()
, and QGraphicsItem::collidesWithItem()
.
public final QGraphicsItemGroup createItemGroup(java.util.List items)
QGraphicsItemGroup
, and returns a pointer to the group. The group is created with the common ancestor of items as its parent, and with position (0, 0). The items are all reparented to the group, and their positions and transformations are mapped to the group. If items is empty, this function will return an empty top-level QGraphicsItemGroup
. QGraphicsScene
has ownership of the group item; you do not need to delete it. To dismantle (ungroup) a group, call destroyItemGroup()
.
destroyItemGroup()
, and QGraphicsItemGroup::addToGroup()
.
public final void destroyItemGroup(QGraphicsItemGroup group)
createItemGroup()
, and QGraphicsItemGroup::removeFromGroup()
.
public final QGraphicsItemInterface focusItem()
The focus item receives keyboard input when the scene receives a key event.
setFocusItem()
, and QGraphicsItem::hasFocus()
.
protected final boolean focusNextPrevChild(boolean next)
You can reimplement this function in a subclass of QGraphicsScene
to provide fine-grained control over how tab focus passes inside your scene. The default implementation is based on the tab focus chain defined by QGraphicsWidget::setTabOrder()
.
public final QFont font()
QApplication::font
. If the scene's font changes, either directly through setFont()
or indirectly when the application font changes, QGraphicsScene
first sends itself a FontChange
event, and it then sends FontChange
events to all top-level widget items in the scene. These items respond by resolving their own fonts to the scene, and they then notify their children, who again notify their children, and so on, until all widget items have updated their fonts.
Changing the scene font, (directly or indirectly through QApplication::setFont()
,) automatically schedules a redraw the entire scene.
QWidget::font
, QApplication::setFont()
, palette
, and style()
.
public final QBrush foregroundBrush()
The foreground is drawn after (on top of) the items. The default foreground brush is Qt::NoBrush
( i.e. the foreground is not drawn).
Example:
QGraphicsScene scene = new QGraphicsScene(); QGraphicsView view = new QGraphicsView(scene); view.show(); // a white semi-transparent foreground scene.setForegroundBrush(new QBrush(new QColor(255, 255, 255, 127))); // a grid foreground scene.setForegroundBrush(new QBrush(QColor.lightGray, Qt.BrushStyle.CrossPattern));
QGraphicsScene::render()
calls drawForeground()
to draw the scene foreground. For more detailed control over how the foreground is drawn, you can reimplement the drawForeground()
function in a QGraphicsScene
subclass.
public final boolean hasFocus()
QKeyEvent
to any item that has focus. setFocus()
, and setFocusItem()
.
public final double height()
width()
.
public final void invalidate(QRectF rect, QGraphicsScene.SceneLayer[] layers)
You can use this function overload to notify QGraphicsScene
of changes to the background or the foreground of the scene. This function is commonly used for scenes with tile-based backgrounds to notify changes when QGraphicsView
has enabled CacheBackground
.
Example:
class TileScene extends QGraphicsScene { private final int tileWidth = 10; private final int tileHeight = 10; private final int numTilesH = 10; private final int numTilesV = 10; private QPixmap[][] tiles; TileScene() { tiles = new QPixmap[numTilesH][numTilesV]; } public QRectF rectForTile(int x, int y) { // Return the rectangle for the tile at position (x, y). return new QRectF(x * tileWidth,y * tileHeight,tileWidth,tileHeight); } public void setTile(int x, int y, QPixmap pixmap) { // Sets or replaces the tile at position (x, y) with pixmap. if (x >= 0 && x < numTilesH && y >= 0 && y < numTilesV) { tiles[y][x] = pixmap; invalidate(rectForTile(x, y), QGraphicsScene.SceneLayer.BackgroundLayer); } } protected void drawBackground(QPainter painter, QRectF exposed) { // Draws all tiles that intersect the exposed area. for (int y = 0; y < numTilesV; ++y) { for (int x = 0; x < numTilesH; ++x) { QRectF rect = rectForTile(x, y); if (exposed.intersects(rect)) painter.drawPixmap(rect.topLeft(), tiles[y][x]); } } } }Note that
QGraphicsView
currently supports background caching only (see QGraphicsView::CacheBackground
). This function is equivalent to calling update()
if any layer but BackgroundLayer
is passed. QGraphicsView::resetCachedContent()
.
public final void invalidate(QRectF rect)
You can use this function overload to notify QGraphicsScene
of changes to the background or the foreground of the scene. This function is commonly used for scenes with tile-based backgrounds to notify changes when QGraphicsView
has enabled CacheBackground
.
Example:
class TileScene extends QGraphicsScene { private final int tileWidth = 10; private final int tileHeight = 10; private final int numTilesH = 10; private final int numTilesV = 10; private QPixmap[][] tiles; TileScene() { tiles = new QPixmap[numTilesH][numTilesV]; } public QRectF rectForTile(int x, int y) { // Return the rectangle for the tile at position (x, y). return new QRectF(x * tileWidth,y * tileHeight,tileWidth,tileHeight); } public void setTile(int x, int y, QPixmap pixmap) { // Sets or replaces the tile at position (x, y) with pixmap. if (x >= 0 && x < numTilesH && y >= 0 && y < numTilesV) { tiles[y][x] = pixmap; invalidate(rectForTile(x, y), QGraphicsScene.SceneLayer.BackgroundLayer); } } protected void drawBackground(QPainter painter, QRectF exposed) { // Draws all tiles that intersect the exposed area. for (int y = 0; y < numTilesV; ++y) { for (int x = 0; x < numTilesH; ++x) { QRectF rect = rectForTile(x, y); if (exposed.intersects(rect)) painter.drawPixmap(rect.topLeft(), tiles[y][x]); } } } }Note that
QGraphicsView
currently supports background caching only (see QGraphicsView::CacheBackground
). This function is equivalent to calling update()
if any layer but BackgroundLayer
is passed. QGraphicsView::resetCachedContent()
.
public final void invalidate()
You can use this function overload to notify QGraphicsScene
of changes to the background or the foreground of the scene. This function is commonly used for scenes with tile-based backgrounds to notify changes when QGraphicsView
has enabled CacheBackground
.
Example:
class TileScene extends QGraphicsScene { private final int tileWidth = 10; private final int tileHeight = 10; private final int numTilesH = 10; private final int numTilesV = 10; private QPixmap[][] tiles; TileScene() { tiles = new QPixmap[numTilesH][numTilesV]; } public QRectF rectForTile(int x, int y) { // Return the rectangle for the tile at position (x, y). return new QRectF(x * tileWidth,y * tileHeight,tileWidth,tileHeight); } public void setTile(int x, int y, QPixmap pixmap) { // Sets or replaces the tile at position (x, y) with pixmap. if (x >= 0 && x < numTilesH && y >= 0 && y < numTilesV) { tiles[y][x] = pixmap; invalidate(rectForTile(x, y), QGraphicsScene.SceneLayer.BackgroundLayer); } } protected void drawBackground(QPainter painter, QRectF exposed) { // Draws all tiles that intersect the exposed area. for (int y = 0; y < numTilesV; ++y) { for (int x = 0; x < numTilesH; ++x) { QRectF rect = rectForTile(x, y); if (exposed.intersects(rect)) painter.drawPixmap(rect.topLeft(), tiles[y][x]); } } } }Note that
QGraphicsView
currently supports background caching only (see QGraphicsView::CacheBackground
). This function is equivalent to calling update()
if any layer but BackgroundLayer
is passed. QGraphicsView::resetCachedContent()
.
public final void invalidate(QRectF rect, QGraphicsScene.SceneLayers layers)
You can use this function overload to notify QGraphicsScene
of changes to the background or the foreground of the scene. This function is commonly used for scenes with tile-based backgrounds to notify changes when QGraphicsView
has enabled CacheBackground
.
Example:
class TileScene extends QGraphicsScene { private final int tileWidth = 10; private final int tileHeight = 10; private final int numTilesH = 10; private final int numTilesV = 10; private QPixmap[][] tiles; TileScene() { tiles = new QPixmap[numTilesH][numTilesV]; } public QRectF rectForTile(int x, int y) { // Return the rectangle for the tile at position (x, y). return new QRectF(x * tileWidth,y * tileHeight,tileWidth,tileHeight); } public void setTile(int x, int y, QPixmap pixmap) { // Sets or replaces the tile at position (x, y) with pixmap. if (x >= 0 && x < numTilesH && y >= 0 && y < numTilesV) { tiles[y][x] = pixmap; invalidate(rectForTile(x, y), QGraphicsScene.SceneLayer.BackgroundLayer); } } protected void drawBackground(QPainter painter, QRectF exposed) { // Draws all tiles that intersect the exposed area. for (int y = 0; y < numTilesV; ++y) { for (int x = 0; x < numTilesH; ++x) { QRectF rect = rectForTile(x, y); if (exposed.intersects(rect)) painter.drawPixmap(rect.topLeft(), tiles[y][x]); } } } }Note that
QGraphicsView
currently supports background caching only (see QGraphicsView::CacheBackground
). This function is equivalent to calling update()
if any layer but BackgroundLayer
is passed. QGraphicsView::resetCachedContent()
.
public final void invalidate(double x, double y, double w, double h, QGraphicsScene.SceneLayer[] layers)
QRectF
(x, y, w, h), layers);
public final void invalidate(double x, double y, double w, double h)
QRectF
(x, y, w, h), layers);
public final void invalidate(double x, double y, double w, double h, QGraphicsScene.SceneLayers layers)
QRectF
(x, y, w, h), layers);
public final QGraphicsItemInterface itemAt(QPointF pos)
items()
, and collidingItems()
.
public final QGraphicsItemInterface itemAt(double x, double y)
This convenience function is equivalent to calling itemAt(QPointF(x, y)).
public final QGraphicsScene.ItemIndexMethod itemIndexMethod()
QGraphicsScene
applies an indexing algorithm to the scene, to speed up item discovery functions like items()
and itemAt()
. Indexing is most efficient for static scenes (i.e., where items don't move around). For dynamic scenes, or scenes with many animated items, the index bookkeeping can outweight the fast lookup speeds. For the common case, the default index method BspTreeIndex
works fine. If your scene uses many animations and you are experiencing slowness, you can disable indexing by calling setItemIndexMethod(NoIndex).
bspTreeDepth
.
public final java.util.List items()
addItem()
, and removeItem()
.
public final java.util.List items(QPainterPath path)
public final java.util.List items(QPainterPath path, Qt.ItemSelectionMode mode)
The default value for mode is Qt::IntersectsItemShape
; all items whose exact shape intersects with or is contained by path are returned.
itemAt()
.
public final java.util.List items(QPointF pos)
itemAt()
.
public final java.util.List items(QPolygonF polygon)
public final java.util.List items(QPolygonF polygon, Qt.ItemSelectionMode mode)
The default value for mode is Qt::IntersectsItemShape
; all items whose exact shape intersects with or is contained by polygon are returned.
itemAt()
.
public final java.util.List items(QRectF rect)
public final java.util.List items(QRectF rect, Qt.ItemSelectionMode mode)
The default value for mode is Qt::IntersectsItemShape
; all items whose exact shape intersects with or is contained by rectangle are returned.
itemAt()
.
public final java.util.List items(double x, double y, double w, double h)
public final java.util.List items(double x, double y, double w, double h, Qt.ItemSelectionMode mode)
QRectF
(x, y, w, h), mode).
public final QRectF itemsBoundingRect()
sceneRect()
.
public final QGraphicsItemInterface mouseGrabberItem()
An item becomes a mouse grabber when it receives and accepts a mouse press event, and it stays the mouse grabber until either of the following events occur:
public final QPalette palette()
QApplication::palette
. If the scene's palette changes, either directly through setPalette()
or indirectly when the application palette changes, QGraphicsScene
first sends itself a PaletteChange
event, and it then sends PaletteChange
events to all top-level widget items in the scene. These items respond by resolving their own palettes to the scene, and they then notify their children, who again notify their children, and so on, until all widget items have updated their palettes.
Changing the scene palette, (directly or indirectly through QApplication::setPalette()
,) automatically schedules a redraw the entire scene.
QWidget::palette
, QApplication::setPalette()
, font
, and style()
.
public final void removeItem(QGraphicsItemInterface item)
QGraphicsScene
will no longer delete item when destroyed). addItem()
.
public final void render(QPainter painter, QRectF target, QRectF source)
QImage
(e.g., to take a screenshot), or for printing with QPrinter
. For example: QGraphicsScene scene = new QGraphicsScene(); scene.addRect(0d,0d,50d,50d); QPrinter printer = new QPrinter(QPrinter.PrinterMode.HighResolution); printer.setPageSize(QPrinter.PageSize.A4); QPainter painter = new QPainter(printer); scene.render(painter);If source is a null rect, this function will use
sceneRect()
to determine what to render. If target is a null rect, the dimensions of painter's paint device will be used. The source rect contents will be transformed according to aspectRatioMode to fit into the target rect. By default, the aspect ratio is kept, and source is scaled to fit in target.
QGraphicsView::render()
.
public final void render(QPainter painter, QRectF target)
QImage
(e.g., to take a screenshot), or for printing with QPrinter
. For example: QGraphicsScene scene = new QGraphicsScene(); scene.addRect(0d,0d,50d,50d); QPrinter printer = new QPrinter(QPrinter.PrinterMode.HighResolution); printer.setPageSize(QPrinter.PageSize.A4); QPainter painter = new QPainter(printer); scene.render(painter);If source is a null rect, this function will use
sceneRect()
to determine what to render. If target is a null rect, the dimensions of painter's paint device will be used. The source rect contents will be transformed according to aspectRatioMode to fit into the target rect. By default, the aspect ratio is kept, and source is scaled to fit in target.
QGraphicsView::render()
.
public final void render(QPainter painter)
QImage
(e.g., to take a screenshot), or for printing with QPrinter
. For example: QGraphicsScene scene = new QGraphicsScene(); scene.addRect(0d,0d,50d,50d); QPrinter printer = new QPrinter(QPrinter.PrinterMode.HighResolution); printer.setPageSize(QPrinter.PageSize.A4); QPainter painter = new QPainter(printer); scene.render(painter);If source is a null rect, this function will use
sceneRect()
to determine what to render. If target is a null rect, the dimensions of painter's paint device will be used. The source rect contents will be transformed according to aspectRatioMode to fit into the target rect. By default, the aspect ratio is kept, and source is scaled to fit in target.
QGraphicsView::render()
.
public final void render(QPainter painter, QRectF target, QRectF source, Qt.AspectRatioMode aspectRatioMode)
QImage
(e.g., to take a screenshot), or for printing with QPrinter
. For example: QGraphicsScene scene = new QGraphicsScene(); scene.addRect(0d,0d,50d,50d); QPrinter printer = new QPrinter(QPrinter.PrinterMode.HighResolution); printer.setPageSize(QPrinter.PageSize.A4); QPainter painter = new QPainter(printer); scene.render(painter);If source is a null rect, this function will use
sceneRect()
to determine what to render. If target is a null rect, the dimensions of painter's paint device will be used. The source rect contents will be transformed according to aspectRatioMode to fit into the target rect. By default, the aspect ratio is kept, and source is scaled to fit in target.
QGraphicsView::render()
.
public final QRectF sceneRect()
QGraphicsView
to determine the view's default scrollable area, and by QGraphicsScene
to manage item indexing. If unset, or if set to a null QRectF
, sceneRect()
will return the largest bounding rect of all items on the scene since the scene was created (i.e., a rectangle that grows when items are added to or moved in the scene, but never shrinks).
width()
, height()
, and QGraphicsView::sceneRect
.
public final java.util.List selectedItems()
setSelectionArea()
.
public final QPainterPath selectionArea()
setSelectionArea()
, or an empty QPainterPath
if no selection area has been set. setSelectionArea()
.
public final void setActiveWindow(QGraphicsWidget widget)
QGraphicsScene
will deactivate any currently active window. activeWindow()
, and QGraphicsWidget::isActiveWindow()
.
public final void setBackgroundBrush(QBrush brush)
Qt::NoBrush
. The background is drawn before (behind) the items. Example:
QGraphicsScene scene = new QGraphicsScene(); QGraphicsView view = new QGraphicsView(scene); view.show(); // a blue background scene.setBackgroundBrush(new QBrush(QColor.blue)); // a gradient background QRadialGradient gradient = new QRadialGradient(0, 0, 10); gradient.setSpread(QGradient.Spread.RepeatSpread); scene.setBackgroundBrush(new QBrush(gradient));
QGraphicsScene::render()
calls drawBackground()
to draw the scene background. For more detailed control over how the background is drawn, you can reimplement drawBackground()
in a subclass of QGraphicsScene
.
public final void setBspTreeDepth(int depth)
QGraphicsScene
's BSP index tree. This property has no effect when NoIndex
is used. This value determines the depth of QGraphicsScene
's BSP tree. The depth directly affects QGraphicsScene
's performance and memory usage; the latter growing exponentially with the depth of the tree. With an optimal tree depth, QGraphicsScene
can instantly determine the locality of items, even for scenes with thousands or millions of items. This also greatly improves rendering performance.
By default, the value is 0, in which case Qt will guess a reasonable default depth based on the size, location and number of items in the scene. If these parameters change frequently, however, you may experience slowdowns as QGraphicsScene
retunes the depth internally. You can avoid potential slowdowns by fixating the tree depth through setting this property.
The depth of the tree and the size of the scene rectangle decide the granularity of the scene's partitioning. The size of each scene segment is determined by the following algorithm:
QSizeF segmentSize = sceneRect().size().divide(java.lang.Math.pow(2, depth - 1));The BSP tree has an optimal size when each segment contains between 0 and 10 items.
itemIndexMethod
.
public final void setFocus()
QFocusEvent
to the scene, passing focusReason as the reason. If the scene regains focus after having previously lost it while an item had focus, the last focus item will receive focus with focusReason as the reason. If the scene already has focus, this function does nothing.
hasFocus()
, clearFocus()
, and setFocusItem()
.
public final void setFocus(Qt.FocusReason focusReason)
QFocusEvent
to the scene, passing focusReason as the reason. If the scene regains focus after having previously lost it while an item had focus, the last focus item will receive focus with focusReason as the reason. If the scene already has focus, this function does nothing.
hasFocus()
, clearFocus()
, and setFocusItem()
.
public final void setFocusItem(QGraphicsItemInterface item)
If item is 0, or if it either does not accept focus (i.e., it does not have the QGraphicsItem::ItemIsFocusable
flag enabled), or is not visible or not enabled, this function only removes focus from any previous focusitem.
If item is not 0, and the scene does not currently have focus (i.e., hasFocus()
returns false), this function will call setFocus()
automatically.
focusItem()
, hasFocus()
, and setFocus()
.
public final void setFocusItem(QGraphicsItemInterface item, Qt.FocusReason focusReason)
If item is 0, or if it either does not accept focus (i.e., it does not have the QGraphicsItem::ItemIsFocusable
flag enabled), or is not visible or not enabled, this function only removes focus from any previous focusitem.
If item is not 0, and the scene does not currently have focus (i.e., hasFocus()
returns false), this function will call setFocus()
automatically.
focusItem()
, hasFocus()
, and setFocus()
.
public final void setFont(QFont font)
QApplication::font
. If the scene's font changes, either directly through setFont()
or indirectly when the application font changes, QGraphicsScene
first sends itself a FontChange
event, and it then sends FontChange
events to all top-level widget items in the scene. These items respond by resolving their own fonts to the scene, and they then notify their children, who again notify their children, and so on, until all widget items have updated their fonts.
Changing the scene font, (directly or indirectly through QApplication::setFont()
,) automatically schedules a redraw the entire scene.
QWidget::font
, QApplication::setFont()
, palette
, and style()
.
public final void setForegroundBrush(QBrush brush)
The foreground is drawn after (on top of) the items. The default foreground brush is Qt::NoBrush
( i.e. the foreground is not drawn).
Example:
QGraphicsScene scene = new QGraphicsScene(); QGraphicsView view = new QGraphicsView(scene); view.show(); // a white semi-transparent foreground scene.setForegroundBrush(new QBrush(new QColor(255, 255, 255, 127))); // a grid foreground scene.setForegroundBrush(new QBrush(QColor.lightGray, Qt.BrushStyle.CrossPattern));
QGraphicsScene::render()
calls drawForeground()
to draw the scene foreground. For more detailed control over how the foreground is drawn, you can reimplement the drawForeground()
function in a QGraphicsScene
subclass.
public final void setItemIndexMethod(QGraphicsScene.ItemIndexMethod method)
QGraphicsScene
applies an indexing algorithm to the scene, to speed up item discovery functions like items()
and itemAt()
. Indexing is most efficient for static scenes (i.e., where items don't move around). For dynamic scenes, or scenes with many animated items, the index bookkeeping can outweight the fast lookup speeds. For the common case, the default index method BspTreeIndex
works fine. If your scene uses many animations and you are experiencing slowness, you can disable indexing by calling setItemIndexMethod(NoIndex).
bspTreeDepth
.
public final void setPalette(QPalette palette)
QApplication::palette
. If the scene's palette changes, either directly through setPalette()
or indirectly when the application palette changes, QGraphicsScene
first sends itself a PaletteChange
event, and it then sends PaletteChange
events to all top-level widget items in the scene. These items respond by resolving their own palettes to the scene, and they then notify their children, who again notify their children, and so on, until all widget items have updated their palettes.
Changing the scene palette, (directly or indirectly through QApplication::setPalette()
,) automatically schedules a redraw the entire scene.
QWidget::palette
, QApplication::setPalette()
, font
, and style()
.
public final void setSceneRect(QRectF rect)
QGraphicsView
to determine the view's default scrollable area, and by QGraphicsScene
to manage item indexing. If unset, or if set to a null QRectF
, sceneRect()
will return the largest bounding rect of all items on the scene since the scene was created (i.e., a rectangle that grows when items are added to or moved in the scene, but never shrinks).
width()
, height()
, and QGraphicsView::sceneRect
.
public final void setSceneRect(double x, double y, double w, double h)
QGraphicsView
to determine the view's default scrollable area, and by QGraphicsScene
to manage item indexing. If unset, or if set to a null QRectF
, sceneRect()
will return the largest bounding rect of all items on the scene since the scene was created (i.e., a rectangle that grows when items are added to or moved in the scene, but never shrinks).
width()
, height()
, and QGraphicsView::sceneRect
.
public final void setSelectionArea(QPainterPath path)
selectedItems()
. For an item to be selected, it must be marked as selectable (QGraphicsItem::ItemIsSelectable
).
clearSelection()
, and selectionArea()
.
public final void setSelectionArea(QPainterPath path, Qt.ItemSelectionMode arg__2)
clearSelection()
, and selectionArea()
.
public final void setStyle(QStyle style)
QApplication::style()
, and serves as the default for all QGraphicsWidget
items in the scene. Changing the style, either directly by calling this function, or indirectly by calling QApplication::setStyle()
, will automatically update the style for all widgets in the scene that do not have a style explicitly assigned to them.
If style is 0, QGraphicsScene
will revert to QApplication::style()
.
style()
.
public final QStyle style()
QApplication::style()
if the scene has not been explicitly assigned a style. setStyle()
.
public final void update()
sceneRect()
, and changed()
.
public final void update(QRectF rect)
sceneRect()
, and changed()
.
public final void update(double x, double y, double w, double h)
QRectF
(x, y, w, h));
public final java.util.List views()
QGraphicsView::scene()
.
public final double width()
sceneRect()
.width()
. height()
.
protected void contextMenuEvent(QGraphicsSceneContextMenuEvent event)
QGraphicsItem::contextMenuEvent()
.
protected void dragEnterEvent(QGraphicsSceneDragDropEvent event)
The default implementation accepts the event and prepares the scene to accept drag move events.
QGraphicsItem::dragEnterEvent()
, dragMoveEvent()
, dragLeaveEvent()
, and dropEvent()
.
protected void dragLeaveEvent(QGraphicsSceneDragDropEvent event)
QGraphicsItem::dragLeaveEvent()
, dragEnterEvent()
, dragMoveEvent()
, and dropEvent()
.
protected void dragMoveEvent(QGraphicsSceneDragDropEvent event)
QGraphicsItem::dragMoveEvent()
, dragEnterEvent()
, dragLeaveEvent()
, and dropEvent()
.
protected void drawBackground(QPainter painter, QRectF rect)
All painting is done in scene coordinates. The rect parameter is the exposed rectangle.
If all you want is to define a color, texture, or gradient for the background, you can call setBackgroundBrush()
instead.
drawForeground()
, and drawItems()
.
protected void drawForeground(QPainter painter, QRectF rect)
All painting is done in scene coordinates. The rect parameter is the exposed rectangle.
If all you want is to define a color, texture or gradient for the foreground, you can call setForegroundBrush()
instead.
drawBackground()
, and drawItems()
.
protected final void drawItems(QPainter painter, QGraphicsItemInterface[] items, QStyleOptionGraphicsItem[] options)
protected void drawItems(QPainter painter, QGraphicsItemInterface[] items, QStyleOptionGraphicsItem[] options, QWidget widget)
protected void dropEvent(QGraphicsSceneDragDropEvent event)
QGraphicsItem::dropEvent()
, dragEnterEvent()
, dragMoveEvent()
, and dragLeaveEvent()
.
protected void focusInEvent(QFocusEvent event)
The default implementation sets focus on the scene, and then on the last focus item.
QGraphicsItem::focusOutEvent()
.
protected void focusOutEvent(QFocusEvent event)
The default implementation removes focus from any focus item, then removes focus from the scene.
QGraphicsItem::focusInEvent()
.
protected void helpEvent(QGraphicsSceneHelpEvent event)
QEvent::ToolTip
, which are created when a tooltip is requested. The default implementation shows the tooltip of the topmost item, i.e., the item with the highest z-value, at the mouse cursor position. If no item has a tooltip set, this function does nothing.
QGraphicsItem::toolTip()
, and QGraphicsSceneHelpEvent
.
protected void inputMethodEvent(QInputMethodEvent event)
The default implementation forwards the event to the focusItem()
. If no item currently has focus, this function does nothing.
QGraphicsItem::inputMethodEvent()
.
public java.lang.Object inputMethodQuery(Qt.InputMethodQuery query)
The query parameter specifies which property is queried.
QWidget::inputMethodQuery()
.
protected void keyPressEvent(QKeyEvent event)
QGraphicsItem::keyPressEvent()
, and focusItem()
.
protected void keyReleaseEvent(QKeyEvent event)
QGraphicsItem::keyReleaseEvent()
, and focusItem()
.
protected void mouseDoubleClickEvent(QGraphicsSceneMouseEvent event)
If someone doubleclicks on the scene, the scene 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. If the doubleclick event is delivered to a different item than the one that received the first press and release, it will be delivered as a press event. However, tripleclick events are not delivered as doubleclick events in this case.
The default implementation is similar to mousePressEvent()
.
QGraphicsItem::mousePressEvent()
, QGraphicsItem::mouseMoveEvent()
, QGraphicsItem::mouseReleaseEvent()
, and QGraphicsItem::setAcceptedMouseButtons()
.
protected void mouseMoveEvent(QGraphicsSceneMouseEvent event)
The default implementation depends on the mouse grabber state. If there is a mouse grabber item, the event is sent to the mouse grabber. If there are any items that accept hover events at the current position, the event is translated into a hover event and accepted; otherwise it's ignored.
QGraphicsItem::mousePressEvent()
, QGraphicsItem::mouseReleaseEvent()
, QGraphicsItem::mouseDoubleClickEvent()
, and QGraphicsItem::setAcceptedMouseButtons()
.
protected void mousePressEvent(QGraphicsSceneMouseEvent event)
The default implementation depends on the state of the scene. If there is a mouse grabber item, then the event is sent to the mouse grabber. Otherwise, it is forwarded to the topmost item that accepts mouse events at the scene position from the event, and that item promptly becomes the mouse grabber item.
If there is no item at the given position on the scene, the selection area is reset, any focus item loses its input focus, and the event is then ignored.
QGraphicsItem::mousePressEvent()
, and QGraphicsItem::setAcceptedMouseButtons()
.
protected void mouseReleaseEvent(QGraphicsSceneMouseEvent event)
The default implementation depends on the mouse grabber state. If there is no mouse grabber, the event is ignored. Otherwise, if there is a mouse grabber item, the event is sent to the mouse grabber. If this mouse release represents the last pressed button on the mouse, the mouse grabber item then loses the mouse grab.
QGraphicsItem::mousePressEvent()
, QGraphicsItem::mouseMoveEvent()
, QGraphicsItem::mouseDoubleClickEvent()
, and QGraphicsItem::setAcceptedMouseButtons()
.
protected void wheelEvent(QGraphicsSceneWheelEvent event)
By default, the event is delivered to the topmost visible item under the cursor. If ignored, the event propagates to the item beneath, and again until the event is accepted, or it reaches the scene. If no items accept the event, it is ignored.
QGraphicsItem::wheelEvent()
.
public static QGraphicsScene fromNativePointer(QNativePointer nativePointer)
public final QGraphicsEllipseItem addEllipse(QRectF rect)
public final QGraphicsEllipseItem addEllipse(QRectF rect, QPen pen)
public final QGraphicsEllipseItem addEllipse(QRectF rect, QPen pen, QBrush brush)
rect
- The bounding rectangle of the ellipse.pen
- The pen for the resulting QGraphicsEllipseItem.brush
- The brush for the resulting QGraphicsEllipseItem.
public final QGraphicsEllipseItem addEllipse(double x, double y, double w, double h)
public final QGraphicsEllipseItem addEllipse(double x, double y, double w, double h, QPen pen)
public final QGraphicsEllipseItem addEllipse(double x, double y, double w, double h, QPen pen, QBrush brush)
x
- The left horizontal coordinate of the ellipse's bounding rectangle.y
- The top vertical coordinate of the ellipse's bounding rectangle.w
- The width of the ellipse's bounding rectangle.h
- The height of the ellipse's bounding rectangle.pen
- The pen for the resulting QGraphicsEllipseItem.brush
- The brush for the resulting QGraphicsEllipseItem.
public final QGraphicsLineItem addLine(QLineF line)
public final QGraphicsLineItem addLine(QLineF line, QPen pen)
line
- The definition of the line.pen
- The pen with which to draw the line.
public final QGraphicsLineItem addLine(double x1, double y1, double x2, double y2)
public final QGraphicsLineItem addLine(double x1, double y1, double x2, double y2, QPen pen)
x1
- The first horizontal coordinate of the line.y1
- The first vertical coordinate of the line.x2
- The second horizontal coordinate of the line.y2
- The second vertical coordinate of the line.pen
- The pen with which to draw the line.
public final QGraphicsPathItem addPath(QPainterPath path)
public final QGraphicsPathItem addPath(QPainterPath path, QPen pen)
public final QGraphicsPathItem addPath(QPainterPath path, QPen pen, QBrush brush)
path
- The definition of the path.pen
- The pen for drawing the path.brush
- The brush for drawing the path.
public final QGraphicsPixmapItem addPixmap(QPixmap pixmap)
pixmap
- The pixmap for which to create a graphics item.
public final QGraphicsPolygonItem addPolygon(QPolygonF polygon)
public final QGraphicsPolygonItem addPolygon(QPolygonF polygon, QPen pen)
public final QGraphicsPolygonItem addPolygon(QPolygonF polygon, QPen pen, QBrush brush)
polygon
- The definition of the polygon.pen
- The pen with which to draw the polygon.brush
- The brush with which to draw the polygon.
public final QGraphicsRectItem addRect(QRectF rect)
public final QGraphicsRectItem addRect(QRectF rect, QPen pen)
public final QGraphicsRectItem addRect(QRectF rect, QPen pen, QBrush brush)
rect
- The definition of the rectangle.pen
- The pen with which to draw the rectangle.brush
- The brush with which to draw the rectangle.
public final QGraphicsRectItem addRect(double x, double y, double w, double h)
public final QGraphicsRectItem addRect(double x, double y, double w, double h, QPen pen)
public final QGraphicsRectItem addRect(double x, double y, double w, double h, QPen pen, QBrush brush)
x
- The left horizontal coordinate of the rectangle.y
- The top vertical coordinate of the rectangle.w
- The width of the rectangle.h
- The height of the rectangle.pen
- The pen with which to draw the rectangle.brush
- The brush with which to draw the rectangle.
public final QGraphicsSimpleTextItem addSimpleText(java.lang.String text)
public final QGraphicsSimpleTextItem addSimpleText(java.lang.String text, QFont font)
text
- The text to add to the scene.font
- The font to use for displaying the text.
public final QGraphicsTextItem addText(java.lang.String text)
public final QGraphicsTextItem addText(java.lang.String text, QFont font)
text
- The text to add to the scene.font
- The font to use for displaying the text.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |