[Interest] formatting bug in QTextEdit

Felix morack felixover at gmail.com
Wed Aug 27 11:33:28 CEST 2014


Hi,

i am trying to change the background color of a couple of lines of text,
the position of the block is given in startlinepos and endlinepos. The best
way appears to be to do this via ExtraSelections with the
FullWidthSelection property.

This works, generally, but the problem is that the last line is not
properly colored completely.

A workaround is to select to the start of the next block, but that fails
when there is no next block.

The problem is probably best visible in the screenshot.

code:

QList<QTextEdit::ExtraSelection> sels;
>
> QTextCharFormat fmt;
> fmt.setProperty(QTextFormat::FullWidthSelection, true);
>
> QTextCursor c = txt->textCursor();
>
> c.setPosition(firstlinepos, QTextCursor::MoveAnchor);
> c.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
>
> c.setPosition(lastlinepos, QTextCursor::KeepAnchor);
> c.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
>
> sel.cursor = c;
> fmt.setBackground(Qt::red);
> sel.format = fmt;
> sels << sel;
>
> txtedit->setExtraSelections(sels);
>

screenshot:

https://i.imgur.com/iQRMDrb.png

is this a bug? or do i misunderstand the meaning of "block" and
"fullwidthselection" in this context?

thanks,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140827/83002729/attachment.html>


More information about the Interest mailing list