Hi,
an old problem is bothering me and I can't get it fixed. After double clicking a custom QGraphicsTextItem, I want to move the cursor of the QTextDocument to the position under the cursor. This is the behavior you can achieve if you press three times the mouse button. So I thought just send a mouse event, but I fail. Here my files:

Qt Code:
  1. #include <QtGui>
  2. #include "myitem.h"
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6. QApplication a(argc, argv);
  7.  
  8. MyItem *it = new MyItem();
  9. it->setPlainText("String to edit");
  10.  
  11. scene.addItem(it);
  12.  
  13. QGraphicsView view(&scene);
  14. view.show();
  15.  
  16. return a.exec();
  17. }
To copy to clipboard, switch view to plain text mode 
Qt Code:
  1. #ifndef MYITEM_H
  2. #define MYITEM_H
  3.  
  4. #include <QtGui>
  5.  
  6. class MyItem : public QGraphicsTextItem
  7. {
  8. Q_OBJECT
  9.  
  10. public:
  11. MyItem(QGraphicsItem *parent = 0);
  12.  
  13. protected:
  14. void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
  15. void focusOutEvent(QFocusEvent *event);
  16. };
  17.  
  18. #endif /* MYITEM_H */
To copy to clipboard, switch view to plain text mode 
Qt Code:
  1. #include "myitem.h"
  2.  
  3. MyItem::MyItem(QGraphicsItem *parent)
  4. {
  5. setTextInteractionFlags(Qt::LinksAccessibleByMouse);
  6. }
  7.  
  8. void MyItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
  9. {
  10. if (textInteractionFlags() & Qt::TextEditorInteraction)
  11. {
  12. QGraphicsTextItem::mouseDoubleClickEvent(event);
  13. }
  14. else
  15. {
  16. setTextInteractionFlags(Qt::TextEditorInteraction);
  17. // HERE SOME MAGIC CODE TO MOVE THE CURSOR
  18. // which is by default at 0 after calling setTextInteractionFlags(Qt::TextEditorInteraction).
  19. }
  20. }
  21.  
  22. void MyItem::focusOutEvent(QFocusEvent *event)
  23. {
  24. setTextInteractionFlags(Qt::LinksAccessibleByMouse);
  25. QGraphicsTextItem::focusOutEvent(event);
  26. }
To copy to clipboard, switch view to plain text mode 

I need to set the editor functionability only after a double click. All attempts to redirect the event leads in a total selection of the text. And creating different QMouseEvents and send them via QCoreApplication::sendEvent ended somewhere in Nirvana...

Any hints are welcome. Even code, as you know I am to lazy to do the work by my own, and it's your job to do my work...

Thanks,

Lykurg