The QGraphicsScene 类提供用于管理大量 2D 图形项的表面。 更多...
头: | #include <QGraphicsScene> |
qmake: | QT += widgets |
Since: | Qt 4.2 |
继承: | QObject |
enum | ItemIndexMethod { BspTreeIndex, NoIndex } |
enum | SceneLayer { ItemLayer, BackgroundLayer, ForegroundLayer, AllLayers } |
flags | SceneLayers |
|
|
QGraphicsScene (QObject * parent = nullptr) | |
QGraphicsScene (const QRectF & sceneRect , QObject * parent = nullptr) | |
QGraphicsScene (qreal x , qreal y , qreal width , qreal height , QObject * parent = nullptr) | |
virtual | ~QGraphicsScene () |
QGraphicsItem * | activePanel () const |
QGraphicsWidget * | activeWindow () const |
QGraphicsEllipseItem * | addEllipse (const QRectF & rect , const QPen & pen = QPen(), const QBrush & brush = QBrush()) |
QGraphicsEllipseItem * | addEllipse (qreal x , qreal y , qreal w , qreal h , const QPen & pen = QPen(), const QBrush & brush = QBrush()) |
void | addItem (QGraphicsItem * item ) |
QGraphicsLineItem * | addLine (const QLineF & line , const QPen & pen = QPen()) |
QGraphicsLineItem * | addLine (qreal x1 , qreal y1 , qreal x2 , qreal y2 , const QPen & pen = QPen()) |
QGraphicsPathItem * | addPath (const QPainterPath & path , const QPen & pen = QPen(), const QBrush & brush = QBrush()) |
QGraphicsPixmapItem * | addPixmap (const QPixmap & pixmap ) |
QGraphicsPolygonItem * | addPolygon (const QPolygonF & polygon , const QPen & pen = QPen(), const QBrush & brush = QBrush()) |
QGraphicsRectItem * | addRect (const QRectF & rect , const QPen & pen = QPen(), const QBrush & brush = QBrush()) |
QGraphicsRectItem * | addRect (qreal x , qreal y , qreal w , qreal h , const QPen & pen = QPen(), const QBrush & brush = QBrush()) |
QGraphicsSimpleTextItem * | addSimpleText (const QString & text , const QFont & font = QFont()) |
QGraphicsTextItem * | addText (const QString & text , const QFont & font = QFont()) |
QGraphicsProxyWidget * | addWidget (QWidget * widget , Qt::WindowFlags wFlags = Qt::WindowFlags()) |
QBrush | backgroundBrush () const |
int | bspTreeDepth () const |
void | clearFocus () |
QList<QGraphicsItem *> | collidingItems (const QGraphicsItem * item , Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const |
QGraphicsItemGroup * | createItemGroup (const QList<QGraphicsItem *> & 项 ) |
void | destroyItemGroup (QGraphicsItemGroup * group ) |
QGraphicsItem * | focusItem () const |
bool | focusOnTouch () const |
QFont | font () const |
QBrush | foregroundBrush () const |
bool | hasFocus () const |
qreal | height () const |
virtual QVariant | inputMethodQuery (Qt::InputMethodQuery query ) const |
void | invalidate (qreal x , qreal y , qreal w , qreal h , QGraphicsScene::SceneLayers layers = AllLayers) |
bool | isActive () const |
QGraphicsItem * | itemAt (const QPointF & position , const QTransform & deviceTransform ) const |
QGraphicsItem * | itemAt (qreal x , qreal y , const QTransform & deviceTransform ) const |
QGraphicsScene::ItemIndexMethod | itemIndexMethod () const |
QList<QGraphicsItem *> | 项 (Qt::SortOrder order = Qt::DescendingOrder) const |
QList<QGraphicsItem *> | 项 (const QPointF & pos , Qt::ItemSelectionMode mode = Qt::IntersectsItemShape, Qt::SortOrder order = Qt::DescendingOrder, const QTransform & deviceTransform = QTransform()) const |
QList<QGraphicsItem *> | 项 (const QRectF & rect , Qt::ItemSelectionMode mode = Qt::IntersectsItemShape, Qt::SortOrder order = Qt::DescendingOrder, const QTransform & deviceTransform = QTransform()) const |
QList<QGraphicsItem *> | 项 (const QPolygonF & polygon , Qt::ItemSelectionMode mode = Qt::IntersectsItemShape, Qt::SortOrder order = Qt::DescendingOrder, const QTransform & deviceTransform = QTransform()) const |
QList<QGraphicsItem *> | 项 (const QPainterPath & path , Qt::ItemSelectionMode mode = Qt::IntersectsItemShape, Qt::SortOrder order = Qt::DescendingOrder, const QTransform & deviceTransform = QTransform()) const |
QList<QGraphicsItem *> | 项 (qreal x , qreal y , qreal w , qreal h , Qt::ItemSelectionMode mode , Qt::SortOrder order , const QTransform & deviceTransform = QTransform()) const |
QRectF | itemsBoundingRect () const |
qreal | minimumRenderSize () const |
QGraphicsItem * | mouseGrabberItem () const |
QPalette | palette () const |
void | removeItem (QGraphicsItem * item ) |
void | render (QPainter * painter , const QRectF & target = QRectF(), const QRectF & source = QRectF(), Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio) |
QRectF | sceneRect () const |
QList<QGraphicsItem *> | selectedItems () const |
QPainterPath | selectionArea () const |
bool | sendEvent (QGraphicsItem * item , QEvent * event ) |
void | setActivePanel (QGraphicsItem * item ) |
void | setActiveWindow (QGraphicsWidget * widget ) |
void | setBackgroundBrush (const QBrush & brush ) |
void | setBspTreeDepth (int depth ) |
void | setFocus (Qt::FocusReason focusReason = Qt::OtherFocusReason) |
void | setFocusItem (QGraphicsItem * item , Qt::FocusReason focusReason = Qt::OtherFocusReason) |
void | setFocusOnTouch (bool enabled ) |
void | setFont (const QFont & font ) |
void | setForegroundBrush (const QBrush & brush ) |
void | setItemIndexMethod (QGraphicsScene::ItemIndexMethod method ) |
void | setMinimumRenderSize (qreal minSize ) |
void | setPalette (const QPalette & palette ) |
void | setSceneRect (const QRectF & rect ) |
void | setSceneRect (qreal x , qreal y , qreal w , qreal h ) |
void | setSelectionArea (const QPainterPath & path , const QTransform & deviceTransform ) |
void | setSelectionArea (const QPainterPath & path , Qt::ItemSelectionMode mode = Qt::IntersectsItemShape, const QTransform & deviceTransform = QTransform()) |
void | setSelectionArea (const QPainterPath & path , Qt::ItemSelectionOperation selectionOperation , Qt::ItemSelectionMode mode = Qt::IntersectsItemShape, const QTransform & deviceTransform = QTransform()) |
void | setStickyFocus (bool enabled ) |
void | setStyle (QStyle * style ) |
bool | stickyFocus () const |
QStyle * | style () const |
void | update (qreal x , qreal y , qreal w , qreal h ) |
QList<QGraphicsView *> | views () const |
qreal | width () const |
void | advance () |
void | clear () |
void | clearSelection () |
void | invalidate (const QRectF & rect = QRectF(), QGraphicsScene::SceneLayers layers = AllLayers) |
void | update (const QRectF & rect = QRectF()) |
void | changed (const QList<QRectF> & region ) |
void | focusItemChanged (QGraphicsItem * newFocusItem , QGraphicsItem * oldFocusItem , Qt::FocusReason reason ) |
void | sceneRectChanged (const QRectF & rect ) |
void | selectionChanged () |
const QMetaObject | staticMetaObject |
virtual void | contextMenuEvent (QGraphicsSceneContextMenuEvent * contextMenuEvent ) |
virtual void | dragEnterEvent (QGraphicsSceneDragDropEvent * event ) |
virtual void | dragLeaveEvent (QGraphicsSceneDragDropEvent * event ) |
virtual void | dragMoveEvent (QGraphicsSceneDragDropEvent * event ) |
virtual void | drawBackground (QPainter * painter , const QRectF & rect ) |
virtual void | drawForeground (QPainter * painter , const QRectF & rect ) |
virtual void | dropEvent (QGraphicsSceneDragDropEvent * event ) |
virtual void | focusInEvent (QFocusEvent * focusEvent ) |
virtual void | focusOutEvent (QFocusEvent * focusEvent ) |
virtual void | helpEvent (QGraphicsSceneHelpEvent * helpEvent ) |
virtual void | inputMethodEvent (QInputMethodEvent * event ) |
virtual void | keyPressEvent (QKeyEvent * keyEvent ) |
virtual void | keyReleaseEvent (QKeyEvent * keyEvent ) |
virtual void | mouseDoubleClickEvent (QGraphicsSceneMouseEvent * mouseEvent ) |
virtual void | mouseMoveEvent (QGraphicsSceneMouseEvent * mouseEvent ) |
virtual void | mousePressEvent (QGraphicsSceneMouseEvent * mouseEvent ) |
virtual void | mouseReleaseEvent (QGraphicsSceneMouseEvent * mouseEvent ) |
virtual void | wheelEvent (QGraphicsSceneWheelEvent * wheelEvent ) |
virtual bool | event (QEvent * event ) override |
virtual bool | eventFilter (QObject * watched , QEvent * event ) override |
bool | focusNextPrevChild (bool next ) |
The QGraphicsScene 类提供用于管理大量 2D 图形项的表面。
类充当 QGraphicsItems 的容器。它被使用同 QGraphicsView for visualizing graphical items, such as lines, rectangles, text, or even custom items, on a 2D surface. QGraphicsScene 属于 图形视图框架 .
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 小部件,可以可视化整个场景,或放大及仅查看场景的一部分。
范例:
QGraphicsScene scene; scene.addText("Hello, world!"); QGraphicsView view(&scene); view.show();
注意, QGraphicsScene has no visual appearance of its own; it only manages the items. You need to create a QGraphicsView 小部件以可视化场景。
To add items to a scene, you start off by constructing a QGraphicsScene object. Then, you have two options: either add your existing QGraphicsItem 对象通过调用 addItem (),或者可以调用某一方便函数 addEllipse (), addLine (), addPath (), addPixmap (), addPolygon (), addRect (),或 addText (),它们都返回指向新近添加项的指针。采用这些函数添加项的尺度相对项坐标系,且场景将项位置初始化为 (0, 0)。
然后,可以可视化场景使用 QGraphicsView . When the scene changes, (e.g., when an item moves or is transformed) QGraphicsScene 发射 changed () 信号。要移除项,调用 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 ()。有关可用索引算法的更多信息,见 itemIndexMethod 特性。
场景边界矩形的设置是通过调用 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 (),作为场景矩形。不管怎样, itemsBoundingRect () 是相对很耗时的函数,因为它通过收集场景中每项的位置信息进行操作。因此,当操作大型场景时,应始终设置场景矩形。
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 项 () 函数可以在几毫秒内确定项的位置。有几个重载对于 项 ():一种在某些位置查找项,一种在多边形或矩形内 (或与多边形或矩形的相交中) 查找项,等等。返回项的列表按堆叠次序排序,最顶项是列表的第一项。为方便起见,还有 itemAt () 函数,返回在给定位置处的最顶项。
QGraphicsScene maintains selection information for the scene. To select items, call setSelectionArea (),和要清零当前选定,调用 clearSelection ()。调用 selectedItems () 以获取所有选中项的列表。
Another responsibility that QGraphicsScene has, is to propagate events from QGraphicsView 。要将事件发送给场景,构造事件继承 QEvent ,然后使用它发送,例如, QApplication::sendEvent (). event () 负责将事件分派给单个项。一些公共事件由方便事件处理程序处理。例如,键按下事件的处理通过 keyPressEvent (),和鼠标按下事件的处理通过 mousePressEvent ().
键事件被交付给 聚焦项 。要设置聚焦项,可以调用 setFocusItem (),传递接受聚焦的项,或者项本身可以调用 QGraphicsItem::setFocus ()。调用 focusItem () 以获取当前聚焦项。为兼容 Widget,场景还维护自己的聚焦信息。默认情况下,场景没有聚焦,且所有键事件都被丢弃。若 setFocus () 被调用,或者若场景项获得聚焦,则场景自动获得聚焦。若场景拥有聚焦, hasFocus () 将返回 true,且键事件会被转发给聚焦项,若有的话。若场景失去聚焦,(即:有人调用 clearFocus ()) 当项有聚焦时,场景将维护其项的聚焦信息,且场景一旦重新获得聚焦,它会确保最后聚焦项重新获得聚焦。
For mouse-over effects, QGraphicsScene dispatches 悬停事件 。若项接受悬停事件 (见 QGraphicsItem::acceptHoverEvents ()),它将接收 GraphicsSceneHoverEnter event when the mouse enters its area. As the mouse continues moving inside the item's area, QGraphicsScene will send it GraphicsSceneHoverMove 事件。当鼠标离开项区域时,项将接收 GraphicsSceneHoverLeave 事件。
所有鼠标事件被交付给当前 鼠标抓取器 项。项变为场景的鼠标抓取器,若它接受鼠标事件 (见 QGraphicsItem::acceptedMouseButtons ()) 和它接收鼠标按下。它保持鼠标抓取器直到收到鼠标释放,当没有按下其它鼠标按钮时。可以调用 mouseGrabberItem () 以确定目前正抓取鼠标的项。
另请参阅 QGraphicsItem and QGraphicsView .
此枚举描述索引算法 QGraphicsScene 提供用于管理场景中项的有关位置信息。
常量 | 值 | 描述 |
---|---|---|
QGraphicsScene::BspTreeIndex
|
0
|
应用 BSP (二进制空间分区) 树。所有 QGraphicsScene 's item location algorithms are of an order close to logarithmic complexity, by making use of binary search. Adding, moving and removing items is logarithmic. This approach is best for static scenes (i.e., scenes where most items do not move). |
QGraphicsScene::NoIndex
|
-1
|
No index is applied. Item location is of linear complexity, as all items on the scene are searched. Adding, moving and removing items, however, is done in constant time. This approach is ideal for dynamic scenes, where many items are added, moved or removed continuously. |
另请参阅 setItemIndexMethod () 和 bspTreeDepth .
此枚举描述渲染层在 QGraphicsScene 。当 QGraphicsScene 绘制场景内容,它按次序单独渲染这些中的每一层。
每层表示可以 OR 在一起的标志当调用函数时,譬如 invalidate () 或 QGraphicsView::invalidateScene ().
常量 | 值 | 描述 |
---|---|---|
QGraphicsScene::ItemLayer
|
0x1
|
项层。 QGraphicsScene 在此层渲染所有项通过调用虚函数 drawItems()。项层的绘制在背景层之后,但在前景层之前。 |
QGraphicsScene::BackgroundLayer
|
0x2
|
背景层。 QGraphicsScene 在此层渲染场景的背景通过调用虚函数 drawBackground ()。在所有层中,首先绘制背景层。 |
QGraphicsScene::ForegroundLayer
|
0x4
|
前景层。 QGraphicsScene 在此层渲染场景的前景通过调用虚函数 drawForeground ()。在所有层中,最后绘制前景层。 |
QGraphicsScene::AllLayers
|
0xffff
|
所有层;此值表示所有 3 层的组合。 |
该枚举在 Qt 4.3 引入或被修改。
SceneLayers 类型是 typedef 对于 QFlags <SceneLayer>。它存储 SceneLayer 值的 OR 组合。
另请参阅 invalidate () 和 QGraphicsView::invalidateScene ().
此特性保持场景的背景画笔。
Set this property to changes the scene's background to a different color, gradient or texture. The default background brush is Qt::NoBrush . The background is drawn before (behind) the items.
范例:
QGraphicsScene scene; QGraphicsView view(&scene); view.show(); // a blue background scene.setBackgroundBrush(Qt::blue); // a gradient background QRadialGradient gradient(0, 0, 10); gradient.setSpread(QGradient::RepeatSpread); scene.setBackgroundBrush(gradient);
QGraphicsScene::render () 调用 drawBackground () to draw the scene background. For more detailed control over how the background is drawn, you can reimplement drawBackground () 在子类化的 QGraphicsScene .
访问函数:
QBrush | backgroundBrush () const |
void | setBackgroundBrush (const QBrush & brush ) |
此特性保持深度为 QGraphicsScene 的 BSP (二进制空间分区) 索引树
此特性不起作用当 NoIndex 被使用。
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() / pow(2, depth - 1);
The BSP tree has an optimal size when each segment contains between 0 and 10 items.
该特性在 Qt 4.3 引入。
访问函数:
int | bspTreeDepth () const |
void | setBspTreeDepth (int depth ) |
另请参阅 itemIndexMethod .
此特性保持项是否获得聚焦,当收到 touch begin 事件。
The usual behavior is to transfer focus only when an item is clicked. Often a tap on a touchpad is interpreted as equivalent to a mouse click by the operating system, generating a synthesized click event in response. However, at least on macOS you can configure this behavior.
默认情况下, QGraphicsScene also transfers focus when you touch on a trackpad or similar. If the operating system is configured to not generate a synthetic mouse click on tapping the trackpad, this is surprising. If the operating system does generate synthetic mouse clicks on tapping the trackpad, the focus transfer on starting a touch gesture is unnecessary.
With focusOnTouch switched off, QGraphicsScene behaves as one would expect on macOS .
默认值为
true
, ensuring that the default behavior is just as in Qt versions prior to 5.12. Set to
false
to prevent touch events from triggering focus changes.
该特性在 Qt 5.12 引入。
访问函数:
bool | focusOnTouch () const |
void | setFocusOnTouch (bool enabled ) |
此特性保持场景的默认字体
This property provides the scene's font. The scene font defaults to, and resolves all its entries from, 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.
该特性在 Qt 4.4 引入。
访问函数:
QFont | font () const |
void | setFont (const QFont & font ) |
另请参阅 QWidget::font , QApplication::setFont (), palette ,和 style ().
此特性保持场景的前景笔刷。
Change this property to set the scene's foreground to a different color, gradient or texture.
The foreground is drawn after (on top of) the items. The default foreground brush is Qt::NoBrush ( i.e. the foreground is not drawn).
范例:
QGraphicsScene scene; QGraphicsView view(&scene); view.show(); // a white semi-transparent foreground scene.setForegroundBrush(QColor(255, 255, 255, 127)); // a grid foreground scene.setForegroundBrush(QBrush(Qt::lightGray, Qt::CrossPattern));
QGraphicsScene::render () 调用 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 子类。
访问函数:
QBrush | foregroundBrush () const |
void | setForegroundBrush (const QBrush & brush ) |
此特性保持项索引方法。
QGraphicsScene applies an indexing algorithm to the scene, to speed up item discovery functions like 项 () 和 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)
.
访问函数:
QGraphicsScene::ItemIndexMethod | itemIndexMethod () const |
void | setItemIndexMethod (QGraphicsScene::ItemIndexMethod method ) |
另请参阅 bspTreeDepth .
此特性保持必须绘制项的最小视图变换大小
When the scene is rendered, any item whose width or height, transformed to the target view, is smaller that minimumRenderSize(), will not be rendered. If an item is not rendered and it clips its children items they will also not be rendered. Set this value to speed up rendering of scenes with many objects rendered on a zoomed out view.
The default value is 0. If unset, or if set to 0 or a negative value, all items will always be rendered.
For example, setting this property can be especially useful if a scene is rendered by multiple views, one of which serves as an overview which always displays all items. In scenes with many items, such a view will use a high scaling factor so that all items can be shown. Due to the scaling, smaller items will only make an insignificant contribution to the final rendered scene. To avoid drawing these items and reduce the time necessary to render the scene, you can call setMinimumRenderSize() with a non-negative value.
注意: Items that are not drawn as a result of being too small, are still returned by methods such as 项 () 和 itemAt (), and participate in collision detection and interactions. It is recommended that you set minimumRenderSize() to a value less than or equal to 1 in order to avoid large unrendered items that are interactive.
该特性在 Qt 5.4 引入。
访问函数:
qreal | minimumRenderSize () const |
void | setMinimumRenderSize (qreal minSize ) |
另请参阅 QStyleOptionGraphicsItem::levelOfDetailFromTransform ().
此特性保持场景的默认调色板
This property provides the scene's palette. The scene palette defaults to, and resolves all its entries from, 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.
改变场景调色板 (直接或间接透过 QApplication::setPalette (),) automatically schedules a redraw the entire scene.
该特性在 Qt 4.4 引入。
访问函数:
QPalette | palette () const |
void | setPalette (const QPalette & palette ) |
另请参阅 QWidget::palette , QApplication::setPalette (), font ,和 style ().
此特性保持场景矩形;场景的边界矩形
场景矩形定义场景范围。首要用于 QGraphicsView 以确定视图的默认可卷动区域,并通过 QGraphicsScene 以管理项索引。
若未设置,或者若设为 null QRectF ,sceneRect() 将返回自场景被创建以来所有场景项的最大边界矩形 (即:矩形变大当项被添加到场景或在场景中移动时,但从不缩小)。
访问函数:
QRectF | sceneRect () const |
void | setSceneRect (const QRectF & rect ) |
void | setSceneRect (qreal x , qreal y , qreal w , qreal h ) |
另请参阅 width (), height (),和 QGraphicsView::sceneRect .
此特性保持点击到场景背景是否清零聚焦
在 QGraphicsScene with stickyFocus set to true, focus will remain unchanged when the user clicks into the scene background or on an item that does not accept focus. Otherwise, focus will be cleared.
默认情况下,此特性为
false
.
聚焦改变是对鼠标按下做出响应。可以重实现 mousePressEvent () 在子类化的 QGraphicsScene 以基于用户点击位置触发此特性。
该特性在 Qt 4.6 引入。
访问函数:
bool | stickyFocus () const |
void | setStickyFocus (bool enabled ) |
另请参阅 clearFocus () 和 setFocusItem ().
构造 QGraphicsScene 对象。 parent 参数会被传递给 QObject 的构造函数。
构造 QGraphicsScene object, using sceneRect 为其场景矩形。 parent 参数会被传递给 QObject 的构造函数。
另请参阅 sceneRect .
构造 QGraphicsScene object, using the rectangle specified by ( x , y ),和给定 width and height 为其场景矩形。 parent 参数会被传递给 QObject 的构造函数。
另请参阅 sceneRect .
[虚拟]
QGraphicsScene::
~QGraphicsScene
()
Removes and deletes all items from the scene object before destroying the scene object. The scene object is removed from the application's global scene list, and it is removed from all associated views.
Returns the current active panel, or 0 if no panel is currently active.
该函数在 Qt 4.6 引入。
另请参阅 QGraphicsScene::setActivePanel ().
Returns the current active window, or 0 if no window is currently active.
该函数在 Qt 4.4 引入。
另请参阅 QGraphicsScene::setActiveWindow ().
创建椭圆项并将其添加到场景,返回项指针。椭圆的几何图形定义通过 rect ,且其钢笔和笔刷被初始化为 pen and brush .
注意:项几何体是按项坐标提供的,且其位置被初始化为 (0, 0)。
若项可见 (即
QGraphicsItem::isVisible
() 返回
true
),
QGraphicsScene
将发射
changed
() 一旦控制回到事件循环。
另请参阅 addLine (), addPath (), addPixmap (), addRect (), addText (), addItem (),和 addWidget ().
此方便函数相当于调用 addEllipse ( QRectF ( x , y , w , h ), pen , brush ).
该函数在 Qt 4.3 引入。
添加或移动 item and all its childen to this scene. This scene takes ownership of the item .
若项可见 (即 QGraphicsItem::isVisible () 返回 true), QGraphicsScene 将发射 changed () 一旦控制回到事件循环。
若项已在不同场景中,将首先从旧场景移除它,然后作为顶层项被添加到此场景。
QGraphicsScene 会将 ItemSceneChange 通知发送给 item 当它被添加到场景时。若项目前不属于场景,则仅发送一个通知。若它已属于场景 (即:它被移到此场景), QGraphicsScene 将发送添加通知,当从先前场景移除项时。
若项是面板,场景活动,且场景中没有活动面板,那么项将被激活。
另请参阅 removeItem (), addEllipse (), addLine (), addPath (), addPixmap (), addRect (), addText (), addWidget (),和 排序 .
Creates and adds a line item to the scene, and returns the item pointer. The geometry of the line is defined by line , and its pen is initialized to pen .
注意:项几何体是按项坐标提供的,且其位置被初始化为 (0, 0)。
若项可见 (即
QGraphicsItem::isVisible
() 返回
true
),
QGraphicsScene
将发射
changed
() 一旦控制回到事件循环。
另请参阅 addEllipse (), addPath (), addPixmap (), addRect (), addText (), addItem (),和 addWidget ().
此方便函数相当于调用 addLine ( QLineF ( x1 , y1 , x2 , y2 ), pen ).
该函数在 Qt 4.3 引入。
创建路径项并将其添加到场景,返回项指针。路径的几何图形定义通过 path ,且其钢笔和笔刷被初始化为 pen and brush .
注意:项几何体是按项坐标提供的,且其位置被初始化为 (0, 0)。
若项可见 (即
QGraphicsItem::isVisible
() 返回
true
),
QGraphicsScene
将发射
changed
() 一旦控制回到事件循环。
另请参阅 addEllipse (), addLine (), addPixmap (), addRect (), addText (), addItem (),和 addWidget ().
创建像素图项并将其添加到场景,返回项指针。像素图的定义通过 pixmap .
注意:项几何体是按项坐标提供的,且其位置被初始化为 (0, 0)。
若项可见 (即
QGraphicsItem::isVisible
() 返回
true
),
QGraphicsScene
将发射
changed
() 一旦控制回到事件循环。
另请参阅 addEllipse (), addLine (), addPath (), addRect (), addText (), addItem (),和 addWidget ().
创建多边形项并将其添加到场景,返回项指针。多边形的定义通过 polygon ,且其钢笔和笔刷被初始化为 pen and brush .
注意:项几何体是按项坐标提供的,且其位置被初始化为 (0, 0)。
若项可见 (即
QGraphicsItem::isVisible
() 返回
true
),
QGraphicsScene
将发射
changed
() 一旦控制回到事件循环。
另请参阅 addEllipse (), addLine (), addPath (), addRect (), addText (), addItem (),和 addWidget ().
创建矩形项并将其添加到场景,返回项指针。矩形的几何图形定义通过 rect ,且其钢笔和笔刷被初始化为 pen and brush .
注意:项几何体是按项坐标提供的,且其位置被初始化为 (0, 0)。例如,若 QRect (50, 50, 100, 100) is added, its top-left corner will be at (50, 50) relative to the origin in the items coordinate system.
若项可见 (即
QGraphicsItem::isVisible
() 返回
true
),
QGraphicsScene
将发射
changed
() 一旦控制回到事件循环。
另请参阅 addEllipse (), addLine (), addPixmap (), addPixmap (), addText (), addItem (),和 addWidget ().
此方便函数相当于调用 addRect ( QRectF ( x , y , w , h ), pen , brush ).
该函数在 Qt 4.3 引入。
创建并添加 QGraphicsSimpleTextItem 到场景,返回项指针。文本字符串被初始化成 text ,且其字体被初始化为 font .
项的位置被初始化为 (0, 0)。
若项可见 (即
QGraphicsItem::isVisible
() 返回
true
),
QGraphicsScene
将发射
changed
() 一旦控制回到事件循环。
另请参阅 addEllipse (), addLine (), addPixmap (), addPixmap (), addRect (), addItem (),和 addWidget ().
创建文本项并将其添加到场景,返回项指针。文本字符串被初始化成 text ,且其字体被初始化为 font .
项的位置被初始化为 (0, 0)。
若项可见 (即
QGraphicsItem::isVisible
() 返回
true
),
QGraphicsScene
将发射
changed
() 一旦控制回到事件循环。
另请参阅 addEllipse (), addLine (), addPixmap (), addPixmap (), addRect (), addItem (),和 addWidget ().
创建新的 QGraphicsProxyWidget for widget ,把它添加到场景,并返回代理指针。 wFlags 为嵌入代理 Widget 设置默认窗口标志。
项的位置被初始化为 (0, 0)。
若项可见 (即
QGraphicsItem::isVisible
() 返回
true
),
QGraphicsScene
将发射
changed
() 一旦控制回到事件循环。
注意:Widget 具有 Qt::WA_PaintOnScreen widget attribute set and widgets that wrap an external application or controller are not supported. Examples are QGLWidget and QAxWidget.
另请参阅 addEllipse (), addLine (), addPixmap (), addPixmap (), addRect (), addText (), addSimpleText (),和 addItem ().
[slot]
void
QGraphicsScene::
advance
()
此槽 advances 场景一步,通过调用 QGraphicsItem::advance () 对于场景中的所有项。这分 2 阶段完成:第 1 阶段,通知所有项场景即将改变,第 2 阶段,通知所有项它们可以移动。在第 1 阶段, QGraphicsItem::advance () 被调用传递 0 值作为自变量,而在第 2 阶段传递 1 值作为自变量。
注意:还可以使用 动画框架 对于动画。
另请参阅 QGraphicsItem::advance () 和 QTimeLine .
[signal]
void
QGraphicsScene::
changed
(const
QList
<
QRectF
> &
region
)
此信号被发射由 QGraphicsScene 当控制到达事件循环时,若场景内容改变。 region 参数包含指示已改变区域的场景矩形的列表。
另请参阅 QGraphicsView::updateScene ().
[slot]
void
QGraphicsScene::
clear
()
从场景移除和删除所有项,否则场景状态保持不变。
该函数在 Qt 4.4 引入。
另请参阅 addItem ().
清零来自场景的聚焦。若任何项有聚焦当调用此函数时,它将失去聚焦并在场景重新再次获得聚焦后重新获得聚焦。
没有聚焦的场景会忽略键事件。
另请参阅 hasFocus (), setFocus (),和 setFocusItem ().
[slot]
void
QGraphicsScene::
clearSelection
()
清零当前选定。
另请参阅 setSelectionArea () 和 selectedItems ().
返回列表的所有项碰撞同 item 。碰撞的确定是通过调用 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 stacking order (i.e., the first item in the list is the uppermost item, and the last item is the lowermost item).
另请参阅 项 (), itemAt (), QGraphicsItem::collidesWithItem (),和 排序 .
[virtual protected]
void
QGraphicsScene::
contextMenuEvent
(
QGraphicsSceneContextMenuEvent
*
contextMenuEvent
)
此事件处理程序用于事件 contextMenuEvent , can be reimplemented in a subclass to receive context menu events. The default implementation forwards the event to the topmost visible item that accepts context menu events at the position of the event. If no items accept context menu events at this position, the event is ignored.
注意:见 项 () 对于通过此函数认为哪些项可见的定义。
另请参阅 QGraphicsItem::contextMenuEvent ().
Groups all items in 项 into a new QGraphicsItemGroup , and returns a pointer to the group. The group is created with the common ancestor of 项 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 项 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 () 和 QGraphicsItemGroup::addToGroup ().
Reparents all items in group to group 's parent item, then removes group from the scene, and finally deletes it. The items' positions and transformations are mapped from the group to the group's parent.
另请参阅 createItemGroup () 和 QGraphicsItemGroup::removeFromGroup ().
[virtual protected]
void
QGraphicsScene::
dragEnterEvent
(
QGraphicsSceneDragDropEvent
*
event
)
此事件处理程序用于事件 event , can be reimplemented in a subclass to receive drag enter events for the scene.
The default implementation accepts the event and prepares the scene to accept drag move events.
另请参阅 QGraphicsItem::dragEnterEvent (), dragMoveEvent (), dragLeaveEvent (),和 dropEvent ().
[virtual protected]
void
QGraphicsScene::
dragLeaveEvent
(
QGraphicsSceneDragDropEvent
*
event
)
此事件处理程序用于事件 event , can be reimplemented in a subclass to receive drag leave events for the scene.
另请参阅 QGraphicsItem::dragLeaveEvent (), dragEnterEvent (), dragMoveEvent (),和 dropEvent ().
[virtual protected]
void
QGraphicsScene::
dragMoveEvent
(
QGraphicsSceneDragDropEvent
*
event
)
此事件处理程序用于事件 event , can be reimplemented in a subclass to receive drag move events for the scene.
注意:见 项 () 对于通过此函数认为哪些项可见的定义。
另请参阅 QGraphicsItem::dragMoveEvent (), dragEnterEvent (), dragLeaveEvent (),和 dropEvent ().
[virtual protected]
void
QGraphicsScene::
drawBackground
(
QPainter
*
painter
, const
QRectF
&
rect
)
绘制场景背景使用 painter , before any items and the foreground are drawn. Reimplement this function to provide a custom background for the scene.
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 () 代替。
另请参阅 drawForeground () 和 drawItems ().
[virtual protected]
void
QGraphicsScene::
drawForeground
(
QPainter
*
painter
, const
QRectF
&
rect
)
Draws the foreground of the scene using painter , after the background and all items have been drawn. Reimplement this function to provide a custom foreground for the scene.
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 () 代替。
另请参阅 drawBackground () 和 drawItems ().
[virtual protected]
void
QGraphicsScene::
dropEvent
(
QGraphicsSceneDragDropEvent
*
event
)
此事件处理程序用于事件 event , can be reimplemented in a subclass to receive drop events for the scene.
另请参阅 QGraphicsItem::dropEvent (), dragEnterEvent (), dragMoveEvent (),和 dragLeaveEvent ().
[override virtual protected]
bool
QGraphicsScene::
event
(
QEvent
*
event
)
重实现自 QObject::event ().
处理事件 event ,并将它分派给各自的事件处理程序。
除调用方便事件处理程序外,此函数负责将鼠标移动事件转换为悬停事件,当不存在鼠标抓取器项时。悬停事件会被直接交付给项;它们没有方便函数。
不像 QWidget , QGraphicsScene 没有方便函数 enterEvent() and leaveEvent() . Use this function to obtain those events instead.
另请参阅 contextMenuEvent (), keyPressEvent (), keyReleaseEvent (), mousePressEvent (), mouseMoveEvent (), mouseReleaseEvent (), mouseDoubleClickEvent (), focusInEvent (),和 focusOutEvent ().
[override virtual protected]
bool
QGraphicsScene::
eventFilter
(
QObject
*
watched
,
QEvent
*
event
)
重实现自 QObject::eventFilter ().
QGraphicsScene 过滤 QApplication 的事件以检测调色板和字体变化。
[virtual protected]
void
QGraphicsScene::
focusInEvent
(
QFocusEvent
*
focusEvent
)
此事件处理程序用于事件 focusEvent , can be reimplemented in a subclass to receive focus in events.
The default implementation sets focus on the scene, and then on the last focus item.
另请参阅 QGraphicsItem::focusOutEvent ().
When the scene is active, this functions returns the scene's current focus item, or 0 if no item currently has focus. When the scene is inactive, this functions returns the item that will gain input focus when the scene becomes active.
The focus item receives keyboard input when the scene receives a key event.
另请参阅 setFocusItem (), QGraphicsItem::hasFocus (),和 isActive ().
[signal]
void
QGraphicsScene::
focusItemChanged
(
QGraphicsItem
*
newFocusItem
,
QGraphicsItem
*
oldFocusItem
,
Qt::FocusReason
reason
)
此信号被发射由 QGraphicsScene 每当场景聚焦改变时 (即:当项获得或失去输入聚焦时,或者当聚焦从一项传递给另一项时)。可以连接到此信号,若需要保持追踪当其它项获得输入聚焦时。它对实现虚拟键盘、输入法及光标项,特别有用。
oldFocusItem 是先前拥有聚焦的项指针,或 0 若在发射信号之前没有项拥有聚焦。 newFocusItem is a pointer to the item that gained input focus, or 0 if focus was lost. reason 是聚焦改变的原因 (如:若场景被取消激活当输入字段拥有聚焦时, oldFocusItem 将指向输入字段项, newFocusItem would be 0, and reason 将为 Qt::ActiveWindowFocusReason .
[protected slot]
bool
QGraphicsScene::
focusNextPrevChild
(
bool
next
)
查找新的 Widget 以赋予键盘聚焦,如适合 Tab 和 Shift+Tab,并返回
true
if it can find a new widget, or false if it cannot. If
next
is true, this function searches forward; if
next
为 False,向后搜索。
可以重实现此函数在子类 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 ().
该函数在 Qt 4.4 引入。
[virtual protected]
void
QGraphicsScene::
focusOutEvent
(
QFocusEvent
*
focusEvent
)
此事件处理程序用于事件 focusEvent , can be reimplemented in a subclass to receive focus out events.
The default implementation removes focus from any focus item, then removes focus from the scene.
另请参阅 QGraphicsItem::focusInEvent ().
返回
true
若场景拥有聚焦;否则返回
false
. If the scene has focus, it will will forward key events from
QKeyEvent
to any item that has focus.
另请参阅 setFocus () 和 setFocusItem ().
此方便函数相当于调用
sceneRect().height()
.
另请参阅 width ().
[virtual protected]
void
QGraphicsScene::
helpEvent
(
QGraphicsSceneHelpEvent
*
helpEvent
)
此事件处理程序用于事件 helpEvent , can be reimplemented in a subclass to receive help events. The events are of type QEvent::ToolTip , which are created when a tooltip is requested.
The default implementation shows the tooltip of the topmost visible 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 () 和 QGraphicsSceneHelpEvent .
[virtual protected]
void
QGraphicsScene::
inputMethodEvent
(
QInputMethodEvent
*
event
)
此事件处理程序用于事件 event ,可以在子类中重实现以接收场景的输入方法事件。
默认实现将事件转发到 focusItem (). If no item currently has focus or the current focus item does not accept input methods, this function does nothing.
另请参阅 QGraphicsItem::inputMethodEvent ().
[虚拟]
QVariant
QGraphicsScene::
inputMethodQuery
(
Qt::InputMethodQuery
query
) const
输入法使用此方法查询场景的一组特性,以便能够支持复杂输入法操作,作为对围绕文本和重新转换的支持。
The query 参数指定要查询的特性。
另请参阅 QWidget::inputMethodQuery ().
[slot]
void
QGraphicsScene::
invalidate
(const
QRectF
&
rect
= QRectF(),
QGraphicsScene::SceneLayers
layers
= AllLayers)
无效并调度重新绘制对于 layers in rect 在场景中。任何缓存内容按 layers 无条件不验证并重新绘制。
可以使用此函数重载以通知 QGraphicsScene 要改变场景的背景 (或前景)。此函数通常用于基于平铺背景的场景,以通知改变当 QGraphicsView 启用 CacheBackground .
范例:
QRectF TileScene::rectForTile(int x, int y) const { // Return the rectangle for the tile at position (x, y). return QRectF(x * tileWidth, y * tileHeight, tileWidth, tileHeight); } void TileScene::setTile(int x, int y, const 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), BackgroundLayer); } } void TileScene::drawBackground(QPainter *painter, const 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]); } } }
注意, QGraphicsView 目前仅支持后台缓存 (见 QGraphicsView::CacheBackground )。此函数相当于调用 update () 若有任何层但 BackgroundLayer 被传递。
另请参阅 QGraphicsView::resetCachedContent ().
这是重载函数。
此方便函数相当于调用 invalidate( QRectF ( x , y , w , h ), layers );
该函数在 Qt 4.3 引入。
返回
true
若场景是活动的 (如:它被查看通过至少一
QGraphicsView
是活动的);否则返回
false
.
该函数在 Qt 4.6 引入。
另请参阅 QGraphicsItem::isActive () 和 QWidget::isActiveWindow ().
返回最顶可见项在指定 position , or 0 if there are no items at this position.
deviceTransform 是应用于视图的变换,且需要提供若场景包含忽略变换的项。
注意:见 项 () 对于通过此函数认为哪些项可见的定义。
该函数在 Qt 4.6 引入。
另请参阅 项 (), collidingItems (),和 排序 .
这是重载函数。
返回最顶可见项在指定位置通过 ( x , y ), or 0 if there are no items at this position.
deviceTransform 是应用于视图的变换,且需要提供若场景包含忽略变换的项。
此方便函数相当于调用
itemAt(QPointF(x, y), deviceTransform)
.
注意:见 项 () 对于通过此函数认为哪些项可见的定义。
该函数在 Qt 4.6 引入。
返回场景中所有项的有序列表。 order 决定堆叠次序。
另请参阅 addItem (), removeItem (),和 排序 .
返回的所有可见项,从属
mode
,在指定
pos
按列表排序使用
order
。在这种情况下,visible 定义项为:isVisible() 返回
true
,effectiveOpacity() 返回大于 0.0 的值 (完全透明),且父级项不裁剪它。
默认值对于 mode is Qt::IntersectsItemShape ;所有项的准确形状相交 pos 被返回。
deviceTransform 是应用于视图的变换,且需要提供若场景包含忽略变换的项。
该函数在 Qt 4.6 引入。
这是重载函数。
返回的所有可见项,从属
mode
,在内部或相交与指定
rect
,按列表排序使用
order
。在这种情况下,visible 定义项为:isVisible() 返回
true
,effectiveOpacity() 返回大于 0.0 的值 (完全透明),且父级项不裁剪它。
默认值对于 mode is Qt::IntersectsItemShape ; all items whose exact shape intersects with or is contained by rect 被返回。
deviceTransform 是应用于视图的变换,且需要提供若场景包含忽略变换的项。
该函数在 Qt 4.6 引入。
这是重载函数。
返回的所有可见项,从属
mode
,在内部或相交与指定
polygon
,按列表排序使用
order
。在这种情况下,visible 定义项为:isVisible() 返回
true
,effectiveOpacity() 返回大于 0.0 的值 (完全透明),且父级项不裁剪它。
默认值对于 mode is Qt::IntersectsItemShape ; all items whose exact shape intersects with or is contained by polygon 被返回。
deviceTransform 是应用于视图的变换,且需要提供若场景包含忽略变换的项。
该函数在 Qt 4.6 引入。
这是重载函数。
返回的所有可见项,从属
mode
,在内部或相交与指定
path
,按列表排序使用
order
。在这种情况下,visible 定义项为:isVisible() 返回
true
,effectiveOpacity() 返回大于 0.0 的值 (完全透明),且父级项不裁剪它。
默认值对于 mode is Qt::IntersectsItemShape ; all items whose exact shape intersects with or is contained by path 被返回。
deviceTransform 是应用于视图的变换,且需要提供若场景包含忽略变换的项。
该函数在 Qt 4.6 引入。
这是重载函数。
返回的所有可见项,从属
mode
, are either inside or intersect with the rectangle defined by
x
,
y
,
w
and
h
,按列表排序使用
order
。在这种情况下,visible 定义项为:isVisible() 返回
true
,effectiveOpacity() 返回大于 0.0 的值 (完全透明),且父级项不裁剪它。
deviceTransform 是应用于视图的变换,且需要提供若场景包含忽略变换的项。
该函数在 Qt 4.6 引入。
计算并返回场景中所有项的边界矩形。此函数通过迭代所有项来工作,因此,对于大型场景它可能很慢。
另请参阅 sceneRect ().
[virtual protected]
void
QGraphicsScene::
keyPressEvent
(
QKeyEvent
*
keyEvent
)
此事件处理程序用于事件 keyEvent ,可以在子类中重实现以接收按键事件。默认实现将事件转发给当前聚焦项。
另请参阅 QGraphicsItem::keyPressEvent () 和 focusItem ().
[virtual protected]
void
QGraphicsScene::
keyReleaseEvent
(
QKeyEvent
*
keyEvent
)
此事件处理程序用于事件 keyEvent ,可以在子类中重实现以接收键释放事件。默认实现将事件转发给当前聚焦项。
另请参阅 QGraphicsItem::keyReleaseEvent () 和 focusItem ().
[virtual protected]
void
QGraphicsScene::
mouseDoubleClickEvent
(
QGraphicsSceneMouseEvent
*
mouseEvent
)
此事件处理程序用于事件 mouseEvent , can be reimplemented in a subclass to receive mouse doubleclick events for the scene.
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.
默认实现类似于 mousePressEvent ().
注意:见 项 () 对于通过此函数认为哪些项可见的定义。
另请参阅 QGraphicsItem::mousePressEvent (), QGraphicsItem::mouseMoveEvent (), QGraphicsItem::mouseReleaseEvent (),和 QGraphicsItem::setAcceptedMouseButtons ().
Returns the current mouse grabber item, or 0 if no item is currently grabbing the mouse. The mouse grabber item is the item that receives all mouse events sent to the scene.
项变为鼠标抓取器当它接收并接受鼠标按下事件时,且它保持鼠标抓取器直到出现以下任一事件为止:
item->setVisible(false)
),或者若它变为被禁用 (即:有人调用
item->setEnabled(false)
),丢失鼠标抓取。
若项丢失鼠标抓取,场景将忽略所有鼠标事件直到新的项抓取鼠标为止 (即:直到新的项接收鼠标按下事件)。
[virtual protected]
void
QGraphicsScene::
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
mouseEvent
)
此事件处理程序用于事件 mouseEvent ,可以在子类中重实现以接收场景鼠标移动事件。
默认实现从属鼠标抓取器状态。若存在鼠标抓取器项,则将事件发送给鼠标抓取器。若当前位置存在接受悬停事件的任何项,则将该事件翻译成悬停事件并接受;否则,它被忽略。
另请参阅 QGraphicsItem::mousePressEvent (), QGraphicsItem::mouseReleaseEvent (), QGraphicsItem::mouseDoubleClickEvent (),和 QGraphicsItem::setAcceptedMouseButtons ().
[virtual protected]
void
QGraphicsScene::
mousePressEvent
(
QGraphicsSceneMouseEvent
*
mouseEvent
)
此事件处理程序用于事件 mouseEvent ,可以在子类中重实现以接收场景的鼠标按下事件。
默认实现从属场景状态。若存在鼠标抓取器项,则将事件发送给鼠标抓取器。否则,从事件将它转发给在场景位置接受鼠标事件的最顶层可见项,且项迅速变为鼠标抓取器项。
若场景中给定位置没有项,则重置选定区域,任何聚焦项失去其输入聚焦,然后事件被忽略。
注意:见 项 () 对于通过此函数认为哪些项可见的定义。
另请参阅 QGraphicsItem::mousePressEvent () 和 QGraphicsItem::setAcceptedMouseButtons ().
[virtual protected]
void
QGraphicsScene::
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
mouseEvent
)
此事件处理程序用于事件 mouseEvent ,可以在子类中重实现以接收场景的鼠标释放事件。
默认实现从属鼠标抓取器状态。若不存在鼠标抓取器,事件被忽略。否则,若存在鼠标抓取器项,事件被发送给鼠标抓取器。若此鼠标释放表示最后按下的鼠标按钮,则鼠标抓取器项丢失鼠标抓取。
另请参阅 QGraphicsItem::mousePressEvent (), QGraphicsItem::mouseMoveEvent (), QGraphicsItem::mouseDoubleClickEvent (),和 QGraphicsItem::setAcceptedMouseButtons ().
移除项 item 及其所有子级从场景。所有权对于 item 被传递给调用者 (即 QGraphicsScene 将不再删除 item 当被销毁时)。
另请参阅 addItem ().
渲染 source 矩形从场景进 target ,使用 painter 。此函数对于将场景内容捕获到绘制设备很有用,譬如 QImage (如:获取屏幕截图),或者为采用 QPrinter 打印。例如:
QGraphicsScene scene; scene.addItem(... ... QPrinter printer(QPrinter::HighResolution); printer.setPaperSize(QPrinter::A4); QPainter painter(&printer); scene.render(&painter);
若 source 是 null 矩形,此函数将使用 sceneRect () 以确定要渲染什么。若 target 是 null 矩形,尺度来自 painter 的描绘设备将被使用。
将变换源矩形内容根据 aspectRatioMode 以拟合到目标矩形。默认情况下,宽高比保持不变,且 source 被比例缩放以拟合到 target .
另请参阅 QGraphicsView::render ().
[signal]
void
QGraphicsScene::
sceneRectChanged
(const
QRectF
&
rect
)
此信号被发射由 QGraphicsScene 每当场景矩形改变时。 rect 参数是新的场景矩形。
另请参阅 QGraphicsView::updateSceneRect ().
返回目前选中的所有项的列表。不按特定次序返回项。
另请参阅 setSelectionArea ().
返回先前设置的选择区域采用 setSelectionArea (),或空 QPainterPath 若未设置选定区域。
另请参阅 setSelectionArea ().
[signal]
void
QGraphicsScene::
selectionChanged
()
此信号被发射由 QGraphicsScene 每当选定改变时。可以调用 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).
该函数在 Qt 4.3 引入。
另请参阅 setSelectionArea (), selectedItems (),和 QGraphicsItem::setSelected ().
发送事件 event 到项 item 透过可能的事件过滤。
才发送事件若项被启用。
返回
false
若事件被过滤或项被禁用。否则返回从事件处理程序返回的值。
该函数在 Qt 4.6 引入。
另请参阅 QGraphicsItem::sceneEvent () 和 QGraphicsItem::sceneEventFilter ().
激活 item ,必须是在此场景中的项。也可以传递 0 对于 item ,在这种情况下 QGraphicsScene 将取消激活任何当前活动面板。
若场景目前不活动, item 仍然不活动直到场景变为活动为止 (或者,若 item is 0, no item will be activated).
该函数在 Qt 4.6 引入。
另请参阅 activePanel (), isActive (),和 QGraphicsItem::isActive ().
激活 widget ,必须是在此场景中的 Widget。也可以传递 0 对于 widget ,在这种情况下 QGraphicsScene 将取消激活任何目前活动的窗口。
该函数在 Qt 4.4 引入。
另请参阅 activeWindow () 和 QGraphicsWidget::isActiveWindow ().
设置聚焦场景通过发送 QFocusEvent 到场景,传递 focusReason 作为原因。若场景重新获得聚焦在拥有焦点的项先前丢失聚焦后,最后聚焦项将接收聚焦采用 focusReason 作为原因。
若场景已聚焦,此函数什么都不做。
另请参阅 hasFocus (), clearFocus (),和 setFocusItem ().
将场景聚焦项设为 item ,采用聚焦原因 focusReason ,在从可能拥有聚焦的任何先前项移除聚焦后。
若 item is 0, or if it either does not accept focus (i.e., it does not have the QGraphicsItem::ItemIsFocusable 启用标志),或不可见或未被启用,此函数仅从任何先前聚焦项移除聚焦。
If item is not 0, and the scene does not currently have focus (i.e.,
hasFocus
() 返回
false
),此函数会调用
setFocus
() 自动。
另请参阅 focusItem (), hasFocus (),和 setFocus ().
将选定区域设为 path 。在此区域内的所有项被立即选中,且在外面的所有项被取消选择。可以获得所有选中项的列表通过调用 selectedItems ().
deviceTransform 是应用于视图的变换,且需要提供若场景包含忽略变换的项。
对于要被选中的项,必须将其标记为 selectable ( QGraphicsItem::ItemIsSelectable ).
该函数在 Qt 4.6 引入。
另请参阅 clearSelection () 和 selectionArea ().
这是重载函数。
将选定区域设为 path 使用 mode 以确定项是否包括在选定区域中。
deviceTransform 是应用于视图的变换,且需要提供若场景包含忽略变换的项。
该函数在 Qt 4.6 引入。
另请参阅 clearSelection () 和 selectionArea ().
这是重载函数。
将选定区域设为 path 使用 mode 以确定项是否包括在选定区域中。
deviceTransform 是应用于视图的变换,且需要提供若场景包含忽略变换的项。
selectionOperation 确定采用目前选定项要做什么。
该函数在 Qt 5.5 引入。
另请参阅 clearSelection () 和 selectionArea ().
将场景样式设置或替换为 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.
若 style 为 0, QGraphicsScene will revert to QApplication::style ().
该函数在 Qt 4.4 引入。
另请参阅 style ().
返回场景样式,或者如同 QApplication::style () 若场景没有明确赋值样式。
该函数在 Qt 4.4 引入。
另请参阅 setStyle ().
[slot]
void
QGraphicsScene::
update
(const
QRectF
&
rect
= QRectF())
调度重新绘制为区域 rect 在场景。
另请参阅 sceneRect () 和 changed ().
这是重载函数。
此函数相当于调用 update( QRectF ( x , y , w , h ));
该函数在 Qt 4.3 引入。
返回显示此场景的所有视图的列表。
另请参阅 QGraphicsView::scene ().
[virtual protected]
void
QGraphicsScene::
wheelEvent
(
QGraphicsSceneWheelEvent
*
wheelEvent
)
此事件处理程序用于事件 wheelEvent ,可以在子类中重实现以接收场景的鼠标滚轮事件。
默认情况下,事件被交付给光标下的最顶可见项。若被忽略,事件将传播给下方项,并再次传播直到事件被接受,或它到达场景。若没有项接受事件,它将被忽略。
注意:见 项 () 对于通过此函数认为哪些项可见的定义。
另请参阅 QGraphicsItem::wheelEvent ().
此方便函数相当于调用 sceneRect ().width().
另请参阅 height ().