Hi,
i am writting a part of a widget that have to display a file and then highlight a line off this file.

The file is properly loaded and the wanted line highlighted but not visible : the QTextEdit widget does not scroll to the cursor position ...

the code is
Qt Code:
  1. //... doing things before ...
  2. //show file
  3. QTextEdit * editor = new QTextEdit(current_body_widget);
  4. editor->setFocus();
  5. {
  6. QString file_to_view = QDir::cleanPath(QString("%1%2%3").arg(build_dir).arg(QDir::separator()).arg(fp.file));
  7. QString error_str;
  8. QFile file( file_to_view );
  9. if ( !file.exists() ) {
  10. error_str = QString( "%1 does not exist." ).arg( file_to_view );
  11. }else{
  12. if ( !file.open( QFile::ReadOnly | QFile::Text ) ) {
  13. error_str = QString( "Cannot open %1" ).arg( file_to_view );
  14. }
  15. }
  16. if(error_str.isEmpty()){
  17. int nb_char=0;
  18. int pos = 0;
  19. int line = 0;
  20. editor->setPlainText( QString("") );
  21. QTextStream in(&file);
  22.  
  23. while(!in.atEnd()){
  24. line++;
  25. if(line == pi.line)
  26. pos = nb_char;
  27. QString line = in.readLine();
  28. editor->append(line);
  29. nb_char+= line.size() + 1; //+1 : '\n'
  30. }
  31.  
  32. //moving cursor
  33. QTextCursor text_cursor = editor->textCursor();
  34. text_cursor.setPosition(pos);
  35.  
  36. text_cursor.select(QTextCursor::BlockUnderCursor);
  37. editor->ensureCursorVisible();
  38. editor->setTextCursor(text_cursor);
  39. }
  40. else
  41. editor->setPlainText( error_str );
  42. //editor->setReadOnly(true);
  43. }
  44.  
  45. editor->update();
  46. layout->addWidget(editor);
  47. //... doing things after ...
To copy to clipboard, switch view to plain text mode 

What am i doing wrong ?