Qt - invalid conversion to child class

Posted by David Davidson on Stack Overflow See other posts from Stack Overflow or by David Davidson
Published on 2010-04-23T13:11:44Z Indexed on 2010/04/23 13:13 UTC
Read the original article Hit count: 291

I'm drawing polygons using the Graphics View framework. I added a polygon to the scene with this:

QGraphicsPolygonItem *poly = scene->addPolygon(QPolygonF(vector_of_QPointF));
poly->setPos(some_point);

But I need to implement some custom behaviour like selection, mouse over indicator, and other similar stuff on the graphics item. So I declared a class that inherits QGraphicsPolygonItem:

#include <QGraphicsPolygonItem>

class GridHex : public QGraphicsPolygonItem
{
public:
    GridHex(QGraphicsItem* parent = 0);
};

GridHex::GridHex(QGraphicsItem* parent) : QGraphicsPolygonItem(parent)
{
}

Not doing much with that class so far, as you can see. But shouldn't replacing QGraphicsPolygonItem with my GridHex class? This is throwing a " invalid conversion from 'QGraphicsPolygonItem*' to 'GridHex*' " error:

GridHex* poly = scene->addPolygon(QPolygonF(vector_of_QPointF));

What am I doing wrong?

© Stack Overflow or respective owner

Related posts about qt

Related posts about qgraphicsview