the are not line. only block and sub fragment from block on QTextedit

at end of one block text break to new line ... but one block can have 10 or more line if no space to display


open all /4.5.0-src/doc/src/snippets / textdocument* to view source sample.....
Only from QT version 4.4 >



To draw on QTextedit you can find each position by iterate block and sub fragment QTextLine

here a sample to grab Blink cursor:

Qt Code:
  1. QLineF ScribePage::BlinkCursorLine()
  2. {
  3. QLineF CursorDrawLine(QPointF(0,0),QPointF(0,10)); /* error line */
  4. /* QTextDocument *_d; */
  5. const QRectF xxtmp = _d->documentLayout()->blockBoundingRect(textCursor().block());
  6. QTextFrame *Tframe = _d->rootFrame();
  7. root_format = Tframe->frameFormat();
  8. QTextLine TTline = currentTextLine(textCursor());
  9. if ( TTline.isValid() ) {
  10. int pos = textCursor().position() - textCursor().block().position();
  11. const qreal TextCursorStartTop = TTline.lineNumber() * TTline.height() + xxtmp.top();
  12. const qreal TextCursorStartLeft = TTline.cursorToX(pos) + root_format.leftMargin() + root_format.padding();
  13. CursorDrawLine = QLineF(QPointF(TextCursorStartLeft,TextCursorStartTop),
  14. QPointF(TextCursorStartLeft,TextCursorStartTop + TTline.height()));
  15. }
  16. return CursorDrawLine;
  17. }
  18.  
  19. QTextLine ScribePage::currentTextLine(const QTextCursor &cursor)
  20. {
  21. const QTextBlock block = cursor.block();
  22. if (!block.isValid())
  23. return QTextLine();
  24.  
  25. const QTextLayout *LayoutBlock = block.layout();
  26. if (!layout)
  27. return QTextLine();
  28. const int relativePos = cursor.position() - block.position();
  29. return LayoutBlock->lineForTextPosition(relativePos);
  30. }
To copy to clipboard, switch view to plain text mode