PDA

View Full Version : Display strings side by side using QLineEdit/QTextEdit



arunvv
14th February 2008, 02:22
Hi all,

How to display strings side by side using QLineEdit / QTextEdit, or is there any other way to display the strings one after the other in the same line.

If I use QTextEdit->append("Text1"); QTextEdit->append("Text2"); // Text2 prints in new line after Text1.
I want Text1 and Text2 should print in same line side by side.
Ex: Text1 <space> Text2 <space> ... etc

How can I do that?

Thanks & Regards,
Arun

jpn
14th February 2008, 05:56
QTextEdit::insertPlainText()

arunvv
14th February 2008, 19:57
Hi

QTextEdit is consuming a lot of CPU load, so to avoid lot of CPU load, I want to go with QLabel, is there any other method from QLabel to write strings side by side as said previously.

Thanks
Arun

jpn
14th February 2008, 21:17
Just append it to its current text. Get the current text, append new stuff, set new text.

abrou
14th February 2008, 21:52
I am not sure if I understand properly, but what I use when trying to do something like that is use QStringLists and the .join() funtion.... It would be something like this, if you were trying to put units at the end of a number....


QString time = "150";
QStringList list;
list << time << "s"; //puts the time, 150 as the first item in the list, then s.
list.join(" "); //putting a space in the quotation marks joins the two strings in the list with a space between the entities.
//this string will now look like "150 s"

you can put this QString in your QLabel, or whatever you chose. I'm sure this isn't the best way, but I like to do it this way.

arunvv
15th February 2008, 02:54
Thanks to all.

Abrou, I am trying to append certain number of strings at the end of current string, it is not just units to append.
I will get some strings/numbers which need to be updated/appended dynamically at the end of current string.
So I was trying to implement with JPN Suggestion.

Get the current text and store it in one string, append new string to current text using normal string functions(like strcat) and using setText to fill this new string to Qlabel.

Thanks & Regards,
Arun.