Hello,
someone knows how these two widgets do paragraph warpping? e.g 25 characters one line.
The goal is to specify a certain block's line length, not the whole document.
e.g
im paragraph 1 im paragraph 1 im paragraph 1 im paragraph 1 im paragraph 1
im paragraph 2
im paragraph 2
im paragraph 2
im paragraph 2
im paragraph 1 im paragraph 1 im paragraph 1 im paragraph 1 im paragraph 1
im paragraph 2
im paragraph 2
im paragraph 2
im paragraph 2
To copy to clipboard, switch view to plain text mode
it could be achieved by adding paragraphbreak at the end of divided lines (so simple)
but i wonder whether i could do it without the hack, because adding break turns the paragraph 2 into 3 4 5...
issue update:
a seemingly working solution after some digging:
// textLayout inherits QPlainTextDocumentLayout
QRectF textLayout
:: blockBoundingRect(const QTextBlock
& block
) const {
// check whether the block is target block need to be wrapped
// ...
// line width in pixel
if (...) {
layout->clearLayout();
qreal height = 0;
layout->beginLayout();
while (true) {
if (! line.isValid())
break;
line.setLineWidth(lineWidth);
line.
setPosition(QPointF(0, height
));
height += line.height();
}
layout->endLayout();
}
return QPlainTextDocumentLayout::blockBoundingRect(block);
}
// textLayout inherits QPlainTextDocumentLayout
QRectF textLayout :: blockBoundingRect(const QTextBlock& block) const
{
// check whether the block is target block need to be wrapped
// ...
// line width in pixel
if (...) {
QTextLayout* layout = block.layout();
layout->clearLayout();
qreal height = 0;
layout->beginLayout();
while (true) {
QTextLine line = layout->createLine();
if (! line.isValid())
break;
line.setLineWidth(lineWidth);
line.setPosition(QPointF(0, height));
height += line.height();
}
layout->endLayout();
}
return QPlainTextDocumentLayout::blockBoundingRect(block);
}
To copy to clipboard, switch view to plain text mode
The text is fine wrapped at the paragraph, but ... scrollbar never comes, what's more, it only works under WidgetWrap Mode.
so the new issues extended:
how to make the scrollbar come?
Bookmarks