[Development] [Interest] QTextEdit - Line Spacing
coroberti .
coroberti at gmail.com
Tue Nov 13 07:50:12 CET 2018
> > Il 11/11/18 17:15, coroberti . ha scritto:
> > > Following Allan's advise, here's something that is starting to work
> > > (checks omitted)
> > >
> > > QTextDocument* doc = this->text_edit_->document();
> > > QTextBlock currentBlock = doc->firstBlock();
> > >
> > > while (currentBlock.isValid()) {
> > >
> > > QTextCursor cursor(currentBlock);
> > > QTextBlockFormat blockFormat = currentBlock.blockFormat();
> > > blockFormat.setLineHeight(200, QTextBlockFormat::ProportionalHeight);
> > > cursor.setBlockFormat(blockFormat);
> > >
> > > currentBlock = currentBlock.next();
> > > }
> > >
> > > Thank you very much!
> >
> > Isn't it simpler to use a selection approach instead?
> >
> > QTextBlockFormat format;
> > format.setLineHeight(...);
> >
> > QTextCursor cursor(textDocument);
> > cursor.select(QTextCursor::Document);
> > cursor.mergeBlockFormat(format);
> > My 2 c,
> > --
> > Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
Thanks, Guiseppe. It also works properly.
Thanks, Allan.
So, there are two good ways from the API point of view.
When HTML from QTextEdit is retrieved by toHtml(), it generates HTML
with the correct line-height, i.e. 200% as in the example below:
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px;
margin-right:0px; -qt-block-indent:0; text-indent:0px;
line-height:200%;">
It's properly treated by browsers, etc.
However, when saved to an html file and next loaded to QTextEdit,
line-height attribute inside <p> tag is ignored.
This page doesn't refer to line-height as to the supported attributes:
http://doc.qt.io/qt-5/richtext-html-subset.html#block-attributes
Is it correct to say that this is not a bug but rather an expected behavior,
and bug report is not required for this case?
Thanks.
Kind regards,
Robert Iakobashvili
............................
More information about the Development
mailing list