Bruschetta
9th November 2016, 14:40
Hello,
i'm new in QT and i'm having problems with QGraphicsItem and my suclassed "Item".
I have a QGraphicsView that contains a QGraphicsScene in which i'm inserting some items.
Those items are a subclass of QGraphicsItem and i have called it TestHoverItem (It contains some additional values).
If i try to get one of the object i have in the QGraphicsScene using the itemAt() function i have no problem (code below)
QGraphicsItem::mousePressEvent(e);
QPoint point = e->scenePos().toPoint();
auto sceneTop = scene();
QGraphicsItem *item = sceneTop->itemAt(point.x(), point.y(),QTransform());
TestHoverItem *hover = qgraphicsitem_cast<TestHoverItem *>(item);
qDebug() << "Codice " << QString::number(hover->getCodice());
If i try to get all the objects from the QGraphicsScene using the items() function the application crashes
QList<QGraphicsItem *> items;
items = sceneTop->items();
qDebug() << "Numero items " + QString::number(items.size());
//Fin qui tutto bene
TestHoverItem * aa= new TestHoverItem();
for(int i=0; i<items.size(); i++){
aa =qgraphicsitem_cast<TestHoverItem *>(items[i]);
qDebug() << "Codice: " +QString::number(aa->getCodice());
}
Can someone explain me what i'm doing wrong?
Thank you for the time and , i hope , for the answers
i'm new in QT and i'm having problems with QGraphicsItem and my suclassed "Item".
I have a QGraphicsView that contains a QGraphicsScene in which i'm inserting some items.
Those items are a subclass of QGraphicsItem and i have called it TestHoverItem (It contains some additional values).
If i try to get one of the object i have in the QGraphicsScene using the itemAt() function i have no problem (code below)
QGraphicsItem::mousePressEvent(e);
QPoint point = e->scenePos().toPoint();
auto sceneTop = scene();
QGraphicsItem *item = sceneTop->itemAt(point.x(), point.y(),QTransform());
TestHoverItem *hover = qgraphicsitem_cast<TestHoverItem *>(item);
qDebug() << "Codice " << QString::number(hover->getCodice());
If i try to get all the objects from the QGraphicsScene using the items() function the application crashes
QList<QGraphicsItem *> items;
items = sceneTop->items();
qDebug() << "Numero items " + QString::number(items.size());
//Fin qui tutto bene
TestHoverItem * aa= new TestHoverItem();
for(int i=0; i<items.size(); i++){
aa =qgraphicsitem_cast<TestHoverItem *>(items[i]);
qDebug() << "Codice: " +QString::number(aa->getCodice());
}
Can someone explain me what i'm doing wrong?
Thank you for the time and , i hope , for the answers