How to mark text as a header in QTextEdit
-
QTextEdit has the ability to read and generate HTML, but I wonder how can I tell it in my code what part of the current document should be a header, or the equivalent for instance of an H1 or H2 tag?
I assume I'd need to set the paragraph style for the selected paragraph however the only API call that I see is setAlignment. -
QTextEdit has the ability to read and generate HTML, but I wonder how can I tell it in my code what part of the current document should be a header, or the equivalent for instance of an H1 or H2 tag?
I assume I'd need to set the paragraph style for the selected paragraph however the only API call that I see is setAlignment.Hi,
QTextDocument is the core interface for that.
Take a look a the Text Edit example. It should give you some nice pointers.
-
Hi,
QTextDocument is the core interface for that.
Take a look a the Text Edit example. It should give you some nice pointers.
-
@SGaist
Thanks that helped. I have a new problem now though:QTextBlockFormat's ident function returns what appear to be incorrect values.
If I pass in HTML, and the text is indented, the indent() method will return 0 even for indented text.
-
@JonB said in How to mark text as a header in QTextEdit:
leftMargin
Oh I was assuming Qt infers the indentation from the left margin value.
Is there a better way using HTML to tell QTextEdit what the indentation level is?
The style text-indent does intent as well, but the indent() method still returns 0.
I tried using <dl><dd> but these didn't cause any indentation at all.
It's the same with <ol>.By the way, just a feature request: It'd be nice if QTextEdit could generate simple HTML, with no CSS at all, like the more rudimentary browsers can understand e.g. Lynx, Links.
-
@JonB said in How to mark text as a header in QTextEdit:
leftMargin
Oh I was assuming Qt infers the indentation from the left margin value.
Is there a better way using HTML to tell QTextEdit what the indentation level is?
The style text-indent does intent as well, but the indent() method still returns 0.
I tried using <dl><dd> but these didn't cause any indentation at all.
It's the same with <ol>.By the way, just a feature request: It'd be nice if QTextEdit could generate simple HTML, with no CSS at all, like the more rudimentary browsers can understand e.g. Lynx, Links.
@clarify
Glancing at sources I can only say/see thatQTextEdit
sets indent in QTextEditPrivate::createAutoBulletList(). For the rest there is a QTextHtmlImporter::import(). For yours maybe you'd have more luck with<ul>
, I don't know.By the way, just a feature request: It'd be nice if QTextEdit could generate simple HTML, with no CSS at all, like the more rudimentary browsers can understand e.g. Lynx, Links.
By now you should know this a user forum, and I am a user just like you, no point requesting features here!
-
J JonB referenced this topic on