I'm trying to figure out how to do a multi-row ListElement property.
I have a ListModel with ListElements like this:
ListElement { key: "key"; value: 1; description: "Very long, full paragraph description that extends way off the screen which I would like to wrap in code nicely." }
I can wrap lines by simply entering a newline character, but subsequent lines will not align with the text block.
description: "Very long, full paragraph description that extends way off the screen which I would like to wrap in code nicely."
When I try to tab on the text to align it, it results in a lot of whitespace when the description prints to the screen (which makes sense, but is obviously not what I want).
description: "Very long, full paragraph description that extends way off the screen which I would like to wrap nicely in code."
Very long, full paragraph description that extends way off the screen which I would like to wrap in code nicely.
I tried connecting via " ", but this produced the error: ListElement: Unable to get property value
using script.
I've tried using backslashes like in the .pro file, but that doesn't work either.
Line breaks work, but they don't matter because they don't solve the whitespace problem.
Very long, full paragraph description that extends way off the screen which I would like to wrap in code nicely.
If anyone has any ideas I would be grateful.
First, you may consider using Javascript backtick notation to declare multi-line strings.
In addition to this, you may find that the
ListElement
declaration is restrictive and does not support Javascript expressions such asDate.now()
. In these cases, you can Consider using imperative code. If you want a somewhat declarative look, you can declare an array of Javascript objects and iterate over it.When rendering, you may also consider using
wrapMode: Text.Wrap
to apply additional word wrapping to format the text.You cantry it online!
I don't have a direct solution for the implementation you are using that creates ListElements directly. But ListModel's .append() method does take a JS object as a parameter. These support multi-line strings. So instead of creating ListElements like this, you can append them when the component is complete like this: