Hi,

i took a QTextEdit and a QSyntaxHighlighter to change the font color of a part of the textedit's first line, for example:

redblue

Now I would like to get the textline back from the textedit, but it's very important to keep the difference between both text fragments ("red" and "blue"). The Qt-manual says I have to do it this way:

Qt Code:
  1. QTextBlock currentBlock = mytextEdit->document()->findBlockByLineNumber(0); //first line
  2.  
  3. QTextBlock::iterator it;
  4. for (it = doc->begin().begin(); !(it.atEnd()); ++it)
  5. {
  6. QTextFragment currentFragment = it.fragment();
  7. if (currentFragment.isValid())
  8. {
  9. QTextCharFormat f = currentFragment.charFormat(); //font of fragment
  10. QString txt = currentFragment.text(); //text of fragment
  11. }
  12. }
To copy to clipboard, switch view to plain text mode 

Usually I should retrieve two QTextFragments, one for "red" and another for "blue", both automatically seperated by their different fonts (look here). But I only retrieve one QTextFragment conatining the whole string "redblue". Also the correspondent QTextCharFormat seems to be empty.

Does anyone know a solution? I use Qt 4.7.4 + VS2010.


With kind regards,
Zygyzy