I found out how to find the index of a point within a scene, namely with the following code:
QList<QGraphicsItem *> lst = this->scene()->items();
QList<QGraphicsItem *>::iterator it = lst.begin();
unsigned i=0;
while (it != lst.end()) {
if((*it) == this){
//(*it)->hide();
qDebug() << "index: " << i;
}
++it;
++i;
}
QList<QGraphicsItem *> lst = this->scene()->items();
QList<QGraphicsItem *>::iterator it = lst.begin();
unsigned i=0;
while (it != lst.end()) {
if((*it) == this){
//(*it)->hide();
qDebug() << "index: " << i;
}
++it;
++i;
}
To copy to clipboard, switch view to plain text mode
and it works, but then I tried to determine the index of the corresponding scene and it does not work. I think it has something to do with the access to a QVector of another class:
QVector<QGraphicsScene *> scenesPhen = main.getScenes();
QVector<QGraphicsScene *>::iterator it2 = scenesPhen.begin();
qDebug() << "scenesPhen.size() = " << scenesPhen.size();
unsigned j=0;
while (it2 != scenesPhen.end()) {
cout << "(*it2): " << (*it2) << "\t\t scene(): "<< scene()<< endl;
if((*it2) == scene()){
qDebug() << "index of scene: " << j;
}
++it2;
++j;
}
QVector<QGraphicsScene *> scenesPhen = main.getScenes();
QVector<QGraphicsScene *>::iterator it2 = scenesPhen.begin();
qDebug() << "scenesPhen.size() = " << scenesPhen.size();
unsigned j=0;
while (it2 != scenesPhen.end()) {
cout << "(*it2): " << (*it2) << "\t\t scene(): "<< scene()<< endl;
if((*it2) == scene()){
qDebug() << "index of scene: " << j;
}
++it2;
++j;
}
To copy to clipboard, switch view to plain text mode
hereby is "main" another class, declared in header file and "getScenes()" is the public function of another class, which gives by the QVector<QGraphicsScene*>.
The cout output gives everytime another combination of addresses, if I move items on different scenes, but actually the addresses of scenes within the scene-vector should remain the same, right? So I guess, that here is somewhere my mistake. But where? Please help...
Thank you
Bookmarks