c++ - Accessing methods of a subclassed QGraphicsRectItem object -
i have subclassed qgraphicsrectitem, named resizablerectitem. have added new member (int index), , 2 methods (getindex() , setindex() ). i'm adding resizablerectitems qgraphicsscene
resizablerectitem* item1 = new resizablerectitem(selrect.normalized()); scene()->additem(item1);
later have call getindex() method, access items on items() of scene(), but
int idx = scene()->items().at(0)->getindex();
is incorrect, because scene()->items() qgraphicsitem , don't have getindex() method. correct solution ? thanks!
what correct solution?
if can re-think logic in code don't have depend on interface of resizablerectitem
, best.
if cannot that, then, you'll need use dynamic_cast
.
qgraphicsrectitem* gitem = scene()->items().at(0); resizablerectitem* item = dynamic_cast<resizablerectitem*>(gitem); if ( item != nullptr ) { int idx = item->getindex(); }
Comments
Post a Comment