[Interest] [Development] QTextEdit - Line Spacing
Allan Sandfeld Jensen
kde at carewolf.com
Tue Nov 13 08:45:06 CET 2018
On Dienstag, 13. November 2018 07:50:12 CET coroberti . wrote:
> > > 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.
>
No I would argue it is a bug, and it is also a bug that line-height is not
listed as a supported property, we are parsing it after all. And if we cant
parse what we write outselves that is pretty silly.
'Allan
More information about the Interest
mailing list