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 *> & items ) |
| 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 *> | items (Qt::SortOrder order = Qt::DescendingOrder) const |
| QList<QGraphicsItem *> | items (const QPointF & pos , Qt::ItemSelectionMode mode = Qt::IntersectsItemShape, Qt::SortOrder order = Qt::DescendingOrder, const QTransform & deviceTransform = QTransform()) const |
| QList<QGraphicsItem *> | items (const QRectF & rect , Qt::ItemSelectionMode mode = Qt::IntersectsItemShape, Qt::SortOrder order = Qt::DescendingOrder, const QTransform & deviceTransform = QTransform()) const |
| QList<QGraphicsItem *> | items (const QPolygonF & polygon , Qt::ItemSelectionMode mode = Qt::IntersectsItemShape, Qt::SortOrder order = Qt::DescendingOrder, const QTransform & deviceTransform = QTransform()) const |
| QList<QGraphicsItem *> | items (const QPainterPath & path , Qt::ItemSelectionMode mode = Qt::IntersectsItemShape, Qt::SortOrder order = Qt::DescendingOrder, const QTransform & deviceTransform = QTransform()) const |
| QList<QGraphicsItem *> | items (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 items () 函數可以在幾毫秒內確定項的位置。有幾個重載對於 items ():一種在某些位置查找項,一種在多邊形或矩形內 (或與多邊形或矩形的相交中) 查找項,等等。返迴項的列錶按堆疊次序排序,最頂項是列錶的第一項。為方便起見,還有 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 items () 和 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 items () 和 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).
另請參閱 items (), 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.
注意:見 items () 對於通過此函數認為哪些項可見的定義。
另請參閱 QGraphicsItem::contextMenuEvent ().
Groups all items in items into a new 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 () 和 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.
注意:見 items () 對於通過此函數認為哪些項可見的定義。
另請參閱 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.
注意:見 items () 對於通過此函數認為哪些項可見的定義。
另請參閱 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 是應用於視圖的變換,且需要提供若場景包含忽略變換的項。
注意:見 items () 對於通過此函數認為哪些項可見的定義。
該函數在 Qt 4.6 引入。
另請參閱 items (), collidingItems (),和 排序 .
這是重載函數。
返迴最頂可見項在指定位置通過 ( x , y ), or 0 if there are no items at this position.
deviceTransform 是應用於視圖的變換,且需要提供若場景包含忽略變換的項。
此方便函數相當於調用
itemAt(QPointF(x, y), deviceTransform)
.
注意:見 items () 對於通過此函數認為哪些項可見的定義。
該函數在 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 ().
注意:見 items () 對於通過此函數認為哪些項可見的定義。
另請參閱 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 ,可以在子類中重實現以接收場景的鼠標按下事件。
默認實現從屬場景狀態。若存在鼠標抓取器項,則將事件發送給鼠標抓取器。否則,從事件將它轉發給在場景位置接受鼠標事件的最頂層可見項,且項迅速變為鼠標抓取器項。
若場景中給定位置沒有項,則重置選定區域,任何聚焦項失去其輸入聚焦,然後事件被忽略。
注意:見 items () 對於通過此函數認為哪些項可見的定義。
另請參閱 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 ,可以在子類中重實現以接收場景的鼠標滾輪事件。
默認情況下,事件被交付給光標下的最頂可見項。若被忽略,事件將傳播給下方項,並再次傳播直到事件被接受,或它到達場景。若沒有項接受事件,它將被忽略。
注意:見 items () 對於通過此函數認為哪些項可見的定義。
另請參閱 QGraphicsItem::wheelEvent ().
此方便函數相當於調用 sceneRect ().width().
另請參閱 height ().