How to put a long string to ListElement?
-
I have to use a long string to ListElements, such as
@ListElement {
myColor: "red"
myText: "This is a very long paragaph This is a very long paragaphThis is a very long paragaphThis is a very long paragaphThis is a very long paragaphThis is a very long paragaphThis is a very long paragaph"
}@
Firstly I think I could use something like
@ListElement {
myColor: "red"
myText: "This is a very long paragaph This is a very long paragaph"
+"This is a very long paragaphThis is a very long paragaph"
+" This is a very long paragaphThis is a very long paragaph"
+"This is a very long paragaph"
}@But The ListElement can not recongnize the + parts. only knows the first line.
Then I try do
@Rectangle {
id:myRect
property string longText: "This is a very long paragaph This is a very long paragaph"
+"This is a very long paragaphThis is a very long paragaph"
+" This is a very long paragaphThis is a very long paragaph"
+"This is a very long paragaph"
ListModel {
ListElement {
myColor: "red"
myText: myRect.longText
}
}
}@And I find ListElement don't allow properties in there data.
Is there a special technique to write a long String in multi-lines, or I have to use a javascript variable?
Thank you.
-
I am not sure I understand your issue, but did you try this:
@Rectangle {
id:myRectListModel {
ListElement {
myColor: "red"
myText: "This is a very long paragaph This is a very long paragaph
This is a very long paragaphThis is a very long paragaph
This is a very long paragaphThis is a very long paragaph
This is a very long paragaph"
}
}
}
@Regards,
Bill -
Thank you for you post. However, the spaces are still recognized. But it is much better than before.
The code below show what I want.
@ Rectangle {
id:myRectListModel { ListElement { myColor: "red" myText: "This is a very long paragaph This is a very long paragaph \
This is a very long paragaphThis is a very long paragaph
This is a very long paragaphThis is a very long paragaph
This is a very long paragaph"
}
}
}
@However, this is ugly when looks at the codes. Any more ideas?
[quote author="billouparis" date="1328882605"]I am not sure I understand your issue, but did you try this:
@Rectangle {
id:myRectListModel {
ListElement {
myColor: "red"
myText: "This is a very long paragaph This is a very long paragaph
This is a very long paragaphThis is a very long paragaph
This is a very long paragaphThis is a very long paragaph
This is a very long paragaph"
}
}
}
@Regards,
Bill
[/quote] -
Why don't you create your list model in C++?
-
Hi,
If we substitute the ListElement myText with the property longText we get the error “ListElement: cannot use script for property value”. Indeed, the property needs a processing that is not allowed. According to "documentation":http://qt-project.org/doc/qt-4.8/qml-listelement.html “Values must be simple constants; either strings (quoted and optionally within a call to QT_TR_NOOP), boolean values (true, false), numbers, or enumeration values (such as AlignText.AlignHCenter). “.
We can use JavaScript arrays for multiline text. See for example "here":http://qt-project.org/wiki/QML_Multi-line_Texts_Handling.Regards
-
Here's a possible solution.
@Rectangle {
id: myrect
width: 360
height: 360
ListView { anchors.fill: parent; model: mymodel;
delegate: Rectangle {
height: 100
width: 360
Text {
anchors.centerIn: parent; text: model.myText; width: parent.width
wrapMode: Text.WordWrap
}
}
}
ListModel {
id: mymodel
}
Component.onCompleted: {mymodel.append({"myColor":"red", "myText": "This is a very long paragaph This is a very long paragaph" +"This is a very long paragaphThis is a very long paragaph" +" This is a very long paragaphThis is a very long paragaph" +"This is a very long paragaph"}); }
}@
-
Very good:). Now the long text is separated in a script block.
-
[quote author="vabo" date="1331546583"]Very good:). Now the long text is separated in a script block.[/quote]
I'm not sure if this is appreciation or sarcasm.
-
Of course admiration! You have added new aspects to the topic.
Regards -
Thank you all for the posts.
I currently use a tricky method that I create a empty listelement part and adding the real part in javascript.