PDA

View Full Version : QPushButton - setText with "\n" not working



gboelter
9th February 2008, 04:47
Sorry, I'm quiet new in Qt and it's possible that somebody will laugh about this question, but I can't found a solution so I would like to ask you guys for al little bit help.

Actually I'm using Qt 4.3 together with Linux and MySQL 5.

From a MySql database I got "Hello\n World" using



QString test1(query.value(1).toString())


In my database "Hello\n World" is stored as varschar(40).

Then for testing I have tried this:



QString test1(query.value(1).toString());
QString test2 = "Hello\n World";

qDebug() << query.value(1); // QVariant(QString, "Hello\World")
qDebug() << test1; // gives me "Hello\n World"
qDebug() << test2; // gives me "Hello
World"


How it comes, that in test1 the newline character is ignored?

Thanks in advance

Guenther
Davao City, Philippines, Planet Earth

wysota
9th February 2008, 09:15
Push buttons don't allow a multiline text. You can use my QwwRichTextButton (http://www.wysota.eu.org/wwwidgets) class if you want or make your own subclass of the button.

gboelter
9th February 2008, 09:33
Push buttons don't allow a multiline text. You can use my QwwRichTextButton (http://www.wysota.eu.org/wwwidgets) class if you want or make your own subclass of the button.

Thanks wysota, I will try it.

What I don't understand is, why it's working with


QString test2 = "Hello\n World";


Here my Button has two lines ....?

marcel
9th February 2008, 09:57
Might be an encoding problem.
Try with:


QString test1(query.value(1).toString().toAscii().constDat a());


Also, in 4.3.3 QPushButtons support multiline strings, it's just they don't resize to the contents by default. See the attachment.

gboelter
9th February 2008, 10:30
[QUOTE=marcel;62576]Might be an encoding problem.
Try with:


QString test1(query.value(1).toString().toAscii().constDat a());


Sorry, still the same ....

:(

marcel
9th February 2008, 10:40
I think the "\" in test1 might be escaped. It is the only explanation.
Try :


int c = test1.count('\');

See what is the value of c.

If it is then you only need to remove one \ from the string.

gboelter
9th February 2008, 17:50
[QUOTE=marcel;62579]I think the "\" in test1 might be escaped. It is the only explanation.

Thanks Marcel, you are right, that was the problem.

Guenther

gboelter
10th February 2008, 03:27
You can use my QwwRichTextButton (http://www.wysota.eu.org/wwwidgets) class if you want or make your own subclass of the button.

Thanks again wysota, I have installed your class and I like it ..... :)