In my code, I have a subclass for QGraphicsScene which I use to create a "worksheet view" and a subclass for QGraphicsTextItem that I use as cells of this worksheet.
What I would like to do is to override the mouseClickEvent such that when I click at a cell, all the cells that have the same plain text will be selected. To do that, I began by getting the cell at the click position. However, when I try to print the plain text, the execution is interrupted.
I have overridden the type function as described in the documentation so I don't see why this is not working.
QtApp.h
class ScheduleSheetCell : public QGraphicsTextItem
{
public:
ScheduleSheetCell(const QString& text);
enum { Type = QGraphicsItem::UserType + 8 };
int type() const override
{
return Type;
}
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
};
class ScheduleScene : public QGraphicsScene
{
public:
ScheduleScene();
protected:
virtual void mousePressEvent (QGraphicsSceneMouseEvent* mouseEvent);
};
QtApp.cpp
void ScheduleScene::mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent)
{
QGraphicsView view = ScheduleScene::views().at(0);
qDebug() << ScheduleScene::items().at(0)->type();
// get scene coords from the view coord
QPointF scenePt = view.mapToScene(mouseEvent->pos().toPoint());
// get the item that was clicked on
auto QtCell = qgraphicsitem_cast <ScheduleSheetCell*>(view.itemAt(scenePt.toPoint()));
qDebug() << QtCell->toPlainText();
}