qt-interest@trolltech.com
[Top] [All Lists]

Re: setText "\n" on a button doesn't work

Subject: Re: setText "\n" on a button doesn't work
From: Harold L Hunt
Date: Wed, 09 Mar 2005 14:21:21 -0800
Song,

If I am not mistaken, the "\n" in your constant string that pass to setText is interpreted by the compiler and replaced with an actual newline character in the string (rather than the \n escape code) that gets included in your binary.

Your XML string that is read from a file, on the other hand, contains the actual two characters "\" and "n", which mean nothing special at run time unless they are passed through a function that looks for them and replaces them with an actual new line character.

On a side note, you can put an actual new line in your XML file and have it come through correctly in the parsed XML file (which can then be passed straight to the button. For example:

<outer>
        <inner>Line one
Line two</inner>
</outer>

The text of <inner> will be:

Line one
Line two

This is what you want instead of <inner>Line one\nLine two</inner>, since that will produce a text of "Line one\nLine two", with the \n instead of a new line.

Hope that helps,

Harold

Song Yun Zhao wrote:
Hi,

I'm trying to set the label on a QPushButton from an XML file. For example, the label is "A very long\nbutton name", basically the idea is to split it so it can fit on the button. But for some reason the button does not interpret the new line ("\n") character. But myButton->setText("A very long\nbutton name") does work.

Does this have anything to do with encoding?

thanks
Song

--
List archive and information: http://lists.trolltech.com/qt-interest/


--
List archive and information: http://lists.trolltech.com/qt-interest/

<Prev in Thread] Current Thread [Next in Thread>