QPushButton - setText with "\n" not working
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
Code:
QString test1
(query.
value(1).
toString())
In my database "Hello\n World" is stored as varschar(40).
Then for testing I have tried this:
Code:
QString test1
(query.
value(1).
toString());
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
Re: QPushButton - setText with "\n" not working
Push buttons don't allow a multiline text. You can use my QwwRichTextButton class if you want or make your own subclass of the button.
Re: QPushButton - setText with "\n" not working
Quote:
Originally Posted by
wysota
Push buttons don't allow a multiline text. You can use my
QwwRichTextButton 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
Here my Button has two lines ....?
1 Attachment(s)
Re: QPushButton - setText with "\n" not working
Might be an encoding problem.
Try with:
Code:
QString test1
(query.
value(1).
toString().
toAscii().
constData());
Also, in 4.3.3 QPushButtons support multiline strings, it's just they don't resize to the contents by default. See the attachment.
Re: QPushButton - setText with "\n" not working
[QUOTE=marcel;62576]Might be an encoding problem.
Try with:
Code:
QString test1
(query.
value(1).
toString().
toAscii().
constData());
Sorry, still the same ....
:(
Re: QPushButton - setText with "\n" not working
I think the "\" in test1 might be escaped. It is the only explanation.
Try :
Code:
int c = test1.count('\');
See what is the value of c.
If it is then you only need to remove one \ from the string.
Re: QPushButton - setText with "\n" not working
[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
Re: QPushButton - setText with "\n" not working
Quote:
Originally Posted by
wysota
You can use my
QwwRichTextButton class if you want or make your own subclass of the button.
Thanks again wysota, I have installed your class and I like it ..... :)