[~~help~~ workaround found] insert a single line break in html (Qt6 RichText)

Hello! I’m writing my application in QML, and inside a TextArea formatted with RichText I want to display this:

a header

(an empty line)

another header

my first thought was to go with a <br> tag, but it has a problem: it creates 2 empty lines, don’t know why. so doing this


<span style="color:#323232;"><</span><span style="color:#63a35c;">h1</span><span style="color:#323232;">>hello</</span><span style="color:#63a35c;">h1</span><span style="color:#323232;">>
</span><span style="color:#323232;"><</span><span style="color:#63a35c;">br</span><span style="color:#323232;">>
</span><span style="color:#323232;"><</span><span style="color:#63a35c;">h2</span><span style="color:#323232;">>world</</span><span style="color:#63a35c;">h2</span><span style="color:#323232;">>
</span>

produces

hello

(an empty line)
(an empty line)

world

I tried using the <pre> tag:


<span style="color:#323232;"><</span><span style="color:#63a35c;">pre</span><span style="color:#323232;">>
</span><span style="color:#323232;"></</span><span style="color:#63a35c;">pre</span><span style="color:#323232;">>
</span>

but no empty lines were displayed

the only working workaround was to use a non breaking space &nbsp;, but being it a TextArea, the user is able to edit the text, and so there would be a “rogue” space instead of an empty line. How can I display just a single line break between two headers (or even paragraphs, but in my case the header is needed)?

tubbadu,
Obscerno,

This is such a weird fix! Good work finding it!

nyan,

It isn’t weird, just sloppy: QT6 seems to be handling this specific tag incorrectly when it presents with HTML void element syntax as defined in section 8.1.2.1 of the HTML 5 standard, which specifies that the slash is allowed but optional. It’s hard to say whether this actually constitutes a QT bug without checking the documentation to see whether it really wants HTML or XHTML, since XHTML does require the slash.

tubbadu,

replying to @ono because for strange reasons I’m unable to reply directly to him:

Does Qt Quick expose Qt’s markdown support? That could be another way to populate a rich text control, perhaps letting you work around the problem.

yes this worked!!!


<span style="font-weight:bold;color:#a71d5d;"># </span><span style="font-weight:bold;color:#323232;">title
</span><span style="color:#a71d5d;"><</span><span style="color:#63a35c;">br</span><span style="color:#a71d5d;"> />
</span><span style="color:#323232;"># title
</span>

I have to use <br /> instead of <br> otherwise it don’t work, I don’t know why

I would have rather used a RichText way, but this one does what I need, thank you very much!

ono,

I have to use <br> instead of <br>

I suspect those two tags were different when you wrote them, and Lemmy mangled them like it did in my comments. Can you describe the tags you originally wrote, to avoid the mangling? I’m curious about what exactly worked for you.

ono,

Does Qt Quick expose Qt’s markdown support? That could be another way to populate a rich text control, perhaps letting you work around the problem.

Creesch,

Have you tried placing the <br> tag directly after the </h1> closing tag?

tubbadu,

I tried, and nothing changed at all

MagicShel,

The mismatch between rich text and html has been a pain for pretty much ever.

Have you tried putting the br on the line above instead of on its own? Barring that can you assign a css class and just create the vertical separation you want?

tubbadu,

thanks for your reply! I tried, and nothing changed at all. I need to create a single editable line between the two headers, so just a spacer wouldn’t be enough. I didn’t think this would be so painful

tubbadu,

replying to @ono as the direct reply loops forever:

thanks for the answer! I already tried an empty paragraph <p></p> but it gets stripped out by the textarea as soon as I assign it to the text property: if I print the text right after it has been modified, the empty paragraph is gone. the same goes for <p[/]> or <[/]p>

ono, (edited )

Just a guess, but have you tried <p></p> ?

Or a single p tag with or without a slash after the p? (Lemmy keeps mangling this one when I write it explicitly.)

doc.qt.io/qt-6/richtext-html-subset.html

mifan,
@mifan@feddit.dk avatar

This. <p> shpuld do the trick.</p>

tubbadu,

If I write some text inside the tags yes, a single line is created, but with the text. I want a blank line, and unfortunately empty tags are apparently stripped out by the textarea

Obscerno,

What about a non-breaking space?

Edit: I just realized you addressed that in the post.

tubbadu,

it’s what I’m currently doing, but was hoping to find a better solution… thank you anyway!

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • uselessserver093
  • Food
  • aaaaaaacccccccce
  • [email protected]
  • test
  • CafeMeta
  • testmag
  • MUD
  • RhythmGameZone
  • RSS
  • dabs
  • Socialism
  • KbinCafe
  • TheResearchGuardian
  • Ask_kbincafe
  • oklahoma
  • feritale
  • SuperSentai
  • KamenRider
  • All magazines