qt字母logo(Class文档的中文翻译)

Detailed Description详细说明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.,我来为大家讲解一下关于qt字母logo?跟着小编一起来看一看吧!

qt字母logo(Class文档的中文翻译)

qt字母logo

Detailed Description详细说明

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.

该类充当QGraphicsItems的容器。它与QGraphicsView一起使用,用于在二维平面上可视化图形项目,如直线、矩形、文本甚至自定义项。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 widget, you can either visualize the whole scene, or zoom in and view only parts of the scene.

QGraphicsScene还提供了功能,让你有效地确定项目的位置,并确定在场景的任意区域内哪些项目可见。使用QGraphicsView部件,你既可以可视化整个场景,也可以放大后仅查看部分场景。

Example:

QGraphicsScene scene;

scene.addText("Hello, world!");

QGraphicsView view(&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.

注意场景本身没有视觉外观,它只管理项目。你需要创建一个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 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.

要向场景中添加项目,首先要构造一个QGraphicsScene对象。然后,你有两个选项:调用addItem()来添加现有的QGraphicsItem对象,或者调用便利函数addEllipse()、addLine()、addPath()、addPixmap()、addPolygon()、addRect()或addText(),它们都返回一个指向新添加项的指针。使用这些函数添加的项目的尺寸相对于项目的坐标系统,并且项目的位置在场景中被初始化为(0,0)。

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.

然后,你可以使用QGraphicsView可视化该场景。当场景改变时(例如,当一个项目移动或坐标变换),QGraphicsScene会发出changed()信号。要删除一个项目,调用removeItem()。QGraphicsScene使用索引算法来有效地管理项目的位置。默认情况下,使用BSP(二进制空间分区)树,是一个适用于大多数物品保持静态(即不移动)的大型场景的算法。你可以选择调用setItemIndexMethod()禁用该索引。有关索引算法的更多信息,请参见itemIndexMethod属性。

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.

场景的边界矩形是通过调用setSceneRect()来设置。项目可以放置在场景中的任何位置,场景的大小默认是无限的。场景矩形仅用于内部簿记,维护场景的项目索引。如果场景矩形未设置,QGraphicsScene将使用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( ) functions can determine the location of an item within a 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最大的优势之一,是它能够有效地确定项目的位置。即使场景中有数百万个项目,items()函数也可以在几毫秒内确定项的位置。items()有几个重载:一个用于查找特定位置的项目,一个用于查找多边形或矩形内部或与之相交的项目,等等。返回的项目列表是按堆叠顺序排序的,最上面的项目是列表中的第一个项目。为了方便起见,还有一个itemAt()函数,它返回给定位置最上面的项目。

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.

QGraphicsScene维护场景的选择信息。要选择项目,调用setSelectionArea(),要清除当前选择,调用clearSelection()。调用selectedItems()获取所有选中项目的列表。

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, QCoreApplication::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().

QGraphicsScene的另一个职责是从QGraphicsView传播事件。要将事件发送到场景,需要构造继承QEvent的事件,然后使用例如QCoreApplication::sendEvent()发送它。Event()负责将事件分派给各个项目。一些常见事件是由便利事件处理程序处理的。例如,按键事件由keyPressEvent()处理,鼠标按压事件由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.

关键事件被传递到焦点项目。要设置焦点项,可调用setFocusItem(),传递项目接受焦点,或者该项目本身能调用QGraphicsItem::setFocus()。调用focusItem()来获取当前的焦点项目。为了与部件兼容,场景还维护自己的焦点信息。默认情况下,场景没有焦点,所有关键事件被丢弃。如果调用setFocus(),或者场景中的一个项目获得焦点,场景就会自动获得焦点。如果场景有焦点,hasFocus()将返回true,关键事件将被转发给焦点项目。如果场景失去焦点(例如,有人调用clearFocus()),而一个项目有焦点,场景将保持它的项目焦点信息,一旦场景重新获得焦点,它将确保最后一个焦点项目重新获得焦点。

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.

对于鼠标悬停效果,QGraphicsScene调度悬停事件。如果一个项目接受悬停事件(参见QGraphicsItem::acceptHoverEvents()),当鼠标进入它的区域时,它将接收一个GraphicsSceneHoverEnter事件。当鼠标继续在项目区域内移动时,QGraphicsScene将发送GraphicsSceneHoverMove事件。当鼠标离开项目所在区域时,项目将收到一个GraphicsSceneHoverLeave事件。

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.

See also QGraphicsItem and QGraphicsView.

所有鼠标事件都传递给当前鼠标抓取器项目。如果一个项目接受了鼠标事件(见QGraphicsItem::acceptedMouseButtons())并接受了鼠标按下,它就会成为场景的鼠标抓取器。当没有按下其他鼠标按钮时,它会一直保持鼠标抓取器状态直到收到鼠标释放。你可以调用mouseGrabberItem()来确定什么项目正在抓取鼠标。也请参见QGraphicsItem和QgraphicsView文档。

,

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页