At last I found the way:
QTextBlock block
= document
()->findBlock
(textCursor
().
position());
QTextLine line
= block.
layout()->lineForTextPosition
(textCursor
().
positionInBlock());
qreal cursor_y_position = document()->documentLayout()->blockBoundingRect(block).y() + line.y();
qreal line_height = line.height();
qDebug("New cursor position: %.2f %.2f", cursor_y_position, line_height);
if ( _actual_position > cursor_y_position )
{
ScrollToPosition(cursor_y_position);
}
if ((_actual_position + _height) < (cursor_y_position + line_height))
{
ScrollToPosition(cursor_y_position + line_height - _height);
}
QGraphicsTextItem::keyPressEvent(event);
QTextBlock block = document()->findBlock(textCursor().position());
QTextLine line = block.layout()->lineForTextPosition(textCursor().positionInBlock());
qreal cursor_y_position = document()->documentLayout()->blockBoundingRect(block).y() + line.y();
qreal line_height = line.height();
qDebug("New cursor position: %.2f %.2f", cursor_y_position, line_height);
if ( _actual_position > cursor_y_position )
{
ScrollToPosition(cursor_y_position);
}
if ((_actual_position + _height) < (cursor_y_position + line_height))
{
ScrollToPosition(cursor_y_position + line_height - _height);
}
To copy to clipboard, switch view to plain text mode
Bookmarks