Qt:Документация 4.3.2/qgraphicsitemgroup
Материал из Wiki.crossplatform.ru
Внимание: Актуальная версия перевода документации находится здесь |
__NOTOC__
Главная · Все классы · Основные классы · Классы по группам · Модули · Функции |
Содержание |
[править] QGraphicsItemGroup Class Reference
[модуль QtGui ]
The QGraphicsItemGroup class provides treating a group of items as one. Далее...
#include <QGraphicsItemGroup>
Inherits QGraphicsItem.
Класс был добавлен в Qt 4.2.
[править] Открытые функции
- QGraphicsItemGroup ( QGraphicsItem * parent = 0 )
- ~QGraphicsItemGroup ()
- void addToGroup ( QGraphicsItem * item )
- void removeFromGroup ( QGraphicsItem * item )
- 114 public functions inherited from QGraphicsItem
[править] Дополнительные унаследованные члены
- 1 static public member inherited from QGraphicsItem
- 23 protected functions inherited from QGraphicsItem
[править] Подробное описание
The QGraphicsItemGroup class provides treating a group of items as one.
A QGraphicsItemGroup is a special type of compound item that treats itself and all its children as one item (i.e., all events and geometries for all children are merged together). It's common to use item groups in presentation tools, when the user wants to group several smaller items into one big item in order to simplify moving and copying of items.
If all you want is to store items inside other items, you can use any QGraphicsItem directly by passing a suitable parent to setParentItem().
The boundingRect() function of QGraphicsItemGroup returns the bounding rectangle of all items in the item group. In addition, item groups have handlesChildEvents() enabled by default, so all events sent to a member of the group go to the item group (i.e., selecting one item in a group will select them all).
There are two ways to construct an item group. The easiest and most common approach is to pass a list of items (e.g., all selected items) to QGraphicsScene::createItemGroup(), which returns a new QGraphicsItemGroup item. The other approach is to manually construct a QGraphicsItemGroup item, add it to the scene calling QGraphicsScene::addItem(), and then add items to the group manually, one at a time by calling addToGroup(). To dismantle ("ungroup") an item group, you can either call QGraphicsScene::destroyItemGroup(), or you can manually remove all items from the group by calling removeFromGroup().
// Group all selected items together QGraphicsItemGroup *group = scene->createItemGroup(scene->selecteditems()); // Destroy the group, and delete the group item scene->destroyItemGroup(group);
The operation of adding and removing items preserves the items' scene-relative position and transformation, as opposed to calling setParentItem(), where only the child item's parent-relative position and transformation are kept.
The addtoGroup() function reparents the target item to this item group, keeping the item's position and transformation intact relative to the scene. Visually, this means that items added via addToGroup() will remain completely unchanged as a result of this operation, regardless of the item or the group's current position or transformation; although the item's position and matrix are likely to change.
The removeFromGroup() function has similar semantics to setParentItem(); it reparents the item to the parent item of the item group. As with addToGroup(), the item's scene-relative position and transformation remain intact.
See also QGraphicsItem and The Graphics View Framework.
[править] Описание функций-членов
[править] QGraphicsItemGroup::QGraphicsItemGroup ( QGraphicsItem * parent = 0 )
Constructs a QGraphicsItemGroup. parent is passed to QGraphicsItem's constructor.
See also QGraphicsScene::addItem().
[править] QGraphicsItemGroup::~QGraphicsItemGroup ()
Destroys the QGraphicsItemGroup.
[править] void QGraphicsItemGroup::addToGroup ( QGraphicsItem * item )
Adds the given item to this item group. The item will be reparented to this group, but its position and transformation relative to the scene will stay intact.
See also removeFromGroup() and QGraphicsScene::createItemGroup().
[править] void QGraphicsItemGroup::removeFromGroup ( QGraphicsItem * item )
Removes the specified item from this group. The item will be reparented to this group's parent item, or to 0 if this group has no parent. Its position and transformation relative to the scene will stay intact.
See also addToGroup() and QGraphicsScene::destroyItemGroup().
Copyright © 2007 Trolltech | Trademarks | Qt 4.3.2
|