PDA

View Full Version : a way to display xml node value with new line (<br/>)



aya_lawliet
31st August 2011, 16:54
Hi,

Is there a way to display new line (<br/>, \n, &#xA; ), read from an xml file, using the Text QML Element?

Currently, I have this xml file:

<?xml version="1.0" encoding="UTF-8"?>
<story>
<pages>
<text>The </text>
<text>quick </text>
<text>brown </text>
<text>fox<![CDATA[<br/>]]></text>
<text>jumps </text>
<text>over </text>
<text>the </text>
<text>lazy </text>
<text>dog.</text>
</pages>
</story>


And I have this qml file to read and display the text read from the xml file


Rectangle {
id: appWindow
width: 300; height: 300
color: "pink"

XmlListModel{
id: xmlmodel
source: "sample.xml"
query: "/story/pages/text"

XmlRole { name: "content"; query: "string()" }
}

Component {
id: itemdelegate
Item {
id: wrapper
width: contentText.width
height: contentText.height
Row {
Text{ id: contentText; text: content; textFormat: Text.PlainText }
}
}
}

Component {
id: highlighter
Rectangle{
color: "yellow"
}
}

ListView {
id: listView
width: 200
height: 20
model: lmodel
delegate: itemdelegate
highlight:highlighter
highlightFollowsCurrentItem: true
orientation: "Horizontal"
}
}

The result only gave me:
The quick brown fox<br/>jumps over the lazy dog.

I have tried using Text.RichText, Text.AutoText, Text.StyledText for the textFormat, but all of them either give me <br/> or did not display at all.

I also tried using only <br/>, instead of enclosing it in CDATA, but i got the same result.

Is there a way to make <br/>, or \n work as it should?

It is imperative that I use an xml file because the texts can be in different languages.

Thank you very much! I hope someone has the answer. :)