[Interest] Multi-line text in QLabel!

395 views
Skip to first unread message

Lata Agrawal

unread,
Mar 31, 2012, 9:41:56 AM3/31/12
to inte...@qt-project.org
Hi,

I am trying to display multi-line string in QLabel. I read this string from an XML file which is of the format:

<?xml version="1.0" encoding="UTF-8"?>
<Feedback>   
    <Ques>
      <text>First Line\nSecond line</text>
    </Ques>
</Feedback>

I don't want to use wordwrap because I want to control where to insert line breaks in the string displayed. In code, I re-formatted the string read from XML file as string read from XML file is converted from \n to \\n.

    QStringList strList = q.questext.split("\\n");
    QString strText = "";
    foreach (QString str, strList)
    {
        strText = str;
        strText += "\n";
        qDebug("strText is %s@@@@@@\n",qPrintable(strText));
    }
    ui->lblQues->setText(strText);

This works fine on Linux_x86 but when I run the same code on Embedded Linux(MIPS), the string appears in a single line ignoring the line breaks. Also the qDebug prints the formatted text properly i.e. with line breaks, on both Linux_x86 and Linux/MIPS.

Can anyone point out whats wrong here?

Regards,
Lata

Bob Hood

unread,
Mar 31, 2012, 9:55:07 AM3/31/12
to inte...@qt-project.org
On 3/31/2012 7:41 AM, Lata Agrawal wrote:
> I don't want to use wordwrap because I want to control where to insert line
> breaks in the string displayed. In code, I re-formatted the string read from
> XML file as string read from XML file is converted from \n to \\n.

I'd probably try changing "\n" to "<br>" and see what that does.

Render me gone, |||
Bob ^(===)^
---------------------------------oOO--(_)--OOo---------------------------------
I'm not so good with advice...can I interest you in a sarcastic comment?

_______________________________________________
Interest mailing list
Inte...@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Lata Agrawal

unread,
Mar 31, 2012, 10:05:56 AM3/31/12
to Bob Hood, inte...@qt-project.org
Hi Bob,

I changed text in XML like this:

<text><br>First Line</br>Second line</text>

Its still displaying in a single line.

SOLVED: But I found the mistake in my code. I had set QLabel have the RichText text format. I removed that and its working now.
Hope that will help someone. if there is a better way of doing it, please let me know.

Thanks & Regards,
Lata
--
                                

Lata Agrawal
Senior Developer
9699750643
En Route Media Pvt. Ltd.
                                

1+1=2

unread,
Mar 31, 2012, 7:38:01 PM3/31/12
to Lata Agrawal, inte...@qt-project.org
Why it does not work is that the text you wrote is wrong in richText.

First Line <br /> Second line.

and In Xml, you need to escape it too.

Reply all
Reply to author
Forward
0 new messages