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

<h1>hello</h1>
<br>
<h2>world</h2>

produces

hello

(an empty line)
(an empty line)

world

I tried using the <pre> tag:

<pre>
</pre>

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)?

3 points
*

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.)

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

permalink
report
reply
1 point

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

permalink
report
parent
reply
1 point

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

permalink
report
parent
reply
2 points
*

What about a non-breaking space?

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

permalink
report
parent
reply
1 point

replying to @ono@lemmy.ca 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 `` or &lt;[/]p>

permalink
report
reply
3 points

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?

permalink
report
reply
2 points

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

permalink
report
parent
reply
1 point

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

permalink
report
reply
1 point

I tried, and nothing changed at all

permalink
report
parent
reply
2 points

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.

permalink
report
reply

Programming

!programming@beehaw.org

Create post

All things programming and coding related. Subcommunity of Technology.


This community’s icon was made by Aaron Schneider, under the CC-BY-NC-SA 4.0 license.

Community stats

  • 67

    Monthly active users

  • 235

    Posts

  • 1.5K

    Comments