Talei
5th April 2014, 23:51
Hello,
I have a question regarding design of multi subclasses item on the scene. I know that's not Qt question but C++ but because of the context I posted it in Qt section, if that's wrong section please move this thread.
What I want to do is to have base class with all common code for the item like this:
class Base : public virtual QGraphicsItem
{
// common code for all items on the scene
};
Next I want some object that are i.e. QGraphicsPixmapItem, QGrapthicsTextItem etc, i.e..
class ItemA : public Base, public QGraphicsPixmapItem
{
QRectF boundingRect() const {
return QGraphicsPixmapItem::boundingRect();
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
painter->drawRoundedRect(-10, -10, 20, 20, 5, 5);
QGraphicsPixmapItem::paint( painter, option, widget);
}
// Only pixmap related code
};
Now I want to control all these objects so I store pointers to objects like:
QList <Base*> itemList;
The problem is ambiguity of QGraphicsItem (in Base) due to the fact that i.e. QGraphicsPixmapItem (and all Qt item classes) are declared as:
class Q_WIDGETS_EXPORT QGraphicsPixmapItem : public QGraphicsItem
My question is how would I go about designing classes that do subclass from i.e. QGraphicsPixmapItem
I have a question regarding design of multi subclasses item on the scene. I know that's not Qt question but C++ but because of the context I posted it in Qt section, if that's wrong section please move this thread.
What I want to do is to have base class with all common code for the item like this:
class Base : public virtual QGraphicsItem
{
// common code for all items on the scene
};
Next I want some object that are i.e. QGraphicsPixmapItem, QGrapthicsTextItem etc, i.e..
class ItemA : public Base, public QGraphicsPixmapItem
{
QRectF boundingRect() const {
return QGraphicsPixmapItem::boundingRect();
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
painter->drawRoundedRect(-10, -10, 20, 20, 5, 5);
QGraphicsPixmapItem::paint( painter, option, widget);
}
// Only pixmap related code
};
Now I want to control all these objects so I store pointers to objects like:
QList <Base*> itemList;
The problem is ambiguity of QGraphicsItem (in Base) due to the fact that i.e. QGraphicsPixmapItem (and all Qt item classes) are declared as:
class Q_WIDGETS_EXPORT QGraphicsPixmapItem : public QGraphicsItem
My question is how would I go about designing classes that do subclass from i.e. QGraphicsPixmapItem