Thanks in advance for your attention ,and excuse me if my speech is not correct .
I am quite new to Qt , I have little experience ,but with books ,examples and documentation I am being able to go on .Anyway ,now I m facing a problem I think I wont solve with more help .
Well , I am making an applicatio that shows some kind of diagram (yes ,very much like the example that comes with Qt ,by the way ,I use Qt 4.4.0 ) .I want some editable text inside the nodes (nodes ares items too) ,so what I thougth is putting a pointer to a QGraphicsTextItem in my class and then filter his events .The parent item of the text item is the node.The behaviour would be : if I click once (on the node or on the text item) I just select the node , if I click twice (not double click) then I start editing the text.
First of all ,I would like to know if it s ok what I am trying .Maybe is not fine to have an item as a data of other item .
Ok ,here is what I do .In the constructor of the node :
myText=new QGraphicsTextItem("Test Text" ,this);
myText->installSceneEventFilter(this);
And here goes sceneEventFilter :
bool DiagramItem::sceneEventFilter(QGraphicsItem * watched, QEvent * event)
{
if(watched==myText){
if(event->type()==QEvent::FocusIn){
QList<QGraphicsItem *> seleccionados = scene()->selectedItems();
if(seleccionados.count()==1 && seleccionados.first()==this){
prev_point=mi_nombre->pos();
myText->setPos(0 , coreBoundingRect().height()/2 + 8 );
myText->update();
prepareGeometryChange();
myText->event(event);
return true;}
else {
sceneEvent(event);
return true;
}
}
else if(event->type()==QEvent::FocusOut){
myText->setPos(prev_point);
//prepareGeometryChange();//do I need this?
myText->event(event);
update();
return true;
}
else {
myText->event(event);
return true;
}
}
return false;
}
Excuse me if the markup is not right .
Maybe I should also filter SceneMousePress and others....but I m not sure .I would realy appreciate your help.
And by the way ,hovers make this annoying to debbug :D
Thank you very much.