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:
QLineF ScribePage
::BlinkCursorLine() {
/* QTextDocument *_d; */
const QRectF xxtmp
= _d
->documentLayout
()->blockBoundingRect
(textCursor
().
block());
root_format = Tframe->frameFormat();
QTextLine TTline
= currentTextLine
(textCursor
());
if ( TTline.isValid() ) {
int pos = textCursor().position() - textCursor().block().position();
const qreal TextCursorStartTop = TTline.lineNumber() * TTline.height() + xxtmp.top();
const qreal TextCursorStartLeft = TTline.cursorToX(pos) + root_format.leftMargin() + root_format.padding();
CursorDrawLine
= QLineF(QPointF(TextCursorStartLeft,TextCursorStartTop
),
QPointF(TextCursorStartLeft,TextCursorStartTop
+ TTline.
height()));
}
return CursorDrawLine;
}
{
if (!block.isValid())
if (!layout)
const int relativePos = cursor.position() - block.position();
return LayoutBlock->lineForTextPosition(relativePos);
}
QLineF ScribePage::BlinkCursorLine()
{
QLineF CursorDrawLine(QPointF(0,0),QPointF(0,10)); /* error line */
/* QTextDocument *_d; */
const QRectF xxtmp = _d->documentLayout()->blockBoundingRect(textCursor().block());
QTextFrame *Tframe = _d->rootFrame();
root_format = Tframe->frameFormat();
QTextLine TTline = currentTextLine(textCursor());
if ( TTline.isValid() ) {
int pos = textCursor().position() - textCursor().block().position();
const qreal TextCursorStartTop = TTline.lineNumber() * TTline.height() + xxtmp.top();
const qreal TextCursorStartLeft = TTline.cursorToX(pos) + root_format.leftMargin() + root_format.padding();
CursorDrawLine = QLineF(QPointF(TextCursorStartLeft,TextCursorStartTop),
QPointF(TextCursorStartLeft,TextCursorStartTop + TTline.height()));
}
return CursorDrawLine;
}
QTextLine ScribePage::currentTextLine(const QTextCursor &cursor)
{
const QTextBlock block = cursor.block();
if (!block.isValid())
return QTextLine();
const QTextLayout *LayoutBlock = block.layout();
if (!layout)
return QTextLine();
const int relativePos = cursor.position() - block.position();
return LayoutBlock->lineForTextPosition(relativePos);
}
To copy to clipboard, switch view to plain text mode
Bookmarks