The code below
QGraphicsEllipseItem *ellipse = addEllipse(x, y, 6, 6, series_pen);
ellipse->translate(-ellipse->boundingRect().width() / 2,
-ellipse->boundingRect().height() / 2);
ellipse->setToolTip(label);
draws the QGraphicsEllipseItem
on a QGraphicsScene
. However, the following code doesn't:
QGraphicsEllipseItem *ellipse = addEllipse(x, y, 6, 6, series_pen);
ellipse->translate(-ellipse->boundingRect().width() / 2,
-ellipse->boundingRect().height() / 2);
ellipse->开发者_开发百科setToolTip(label);
QGraphicsItemGroup *g = new QGraphicsItemGroup;
g->addToGroup(ellipse);
What is wrong if I add a QGraphicsItem
in QGraphicsItemGroup
?
I'm using Qt Creator 2.2.1, Qt 4.7.4 (32 bit) on Windows 7.
From the Qt manual page for QGraphicsItemGroup:
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().
Sounds like your code needs to call QGraphicsScene::addItem().
QGraphicsItemGroup
is also a QGraphicsItem
, so you need to add it to the scene, for its children to be drawn too.
精彩评论