I've subclassed QGraphicsItem into my own custom class, Hexagon. When I try to use a function such as QGraphicsView::itemAt
, or QGraphicsScene::itemAt
, it won't return any of my Hexagon
objects because the function instead looks for QGraphicsItems
.
How can I tell it to look for Hexagon
objects instead? Or do I need to change something in my Hexagon
class? Or even re-implement itemAt()
?
Currently, I'm also subclassing QGraphicsView
, particlarly mousePressedEvent
to get some info about the Hexagon
object that is clicked on.
void LatticeView::mousePressEvent(QMouseEvent *event)
{
Hexagon *hexagon = itemAt(event->pos());
...
}
But when I try to compile, I get the following error:
invalid conversion from 'QGraphicsItem*' to 'Hexagon*'
What I want is to be able to get the Hexagon
object that is clicked on so that I can access some variables I've defined in the Hexagon
class that are not implicit in the QGraphicsItem
class.