Let's suppose that there is a scene with several custom QGraphicsItem's. And each such item has ability to scale (I place special anchors to the corners). It work good, as expected.
Now I want to group some of items with QGraphicsItemGroup and I would like to add same scale ability into group item.
Below is an example of my code:
class Base : public QGraphicsItem
{
public:
Base(QGraphicsItem * parent = 0);
...
// I implement scaling with these functions:
void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
void mousePressEvent(QGraphicsSceneMouseEvent * event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
}
class Item : public Base
{
public:
Item(QGraphicsItem * parent = 0);
QRectF boundingRect() const;
void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0);
}
class Group : public Base,QGraphicsItemGroup
{
public:
Group(QGraphicsItem * parent = 0);
}
I can compile this code but when I add something like scene.addItem(item)
when item
is instance of Group
or Item
I get error:
request for member 'addItem' is ambiguous
And this error is understandable. There are 2 parent of type QGraphicsItem for the object and compiler just discouraged in this case. So my question - how can I avoid it? I don't want to copy same code (for scaling) into 2 classes.