Results 1 to 6 of 6

Thread: Display strings side by side using QLineEdit/QTextEdit

  1. #1
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Display strings side by side using QLineEdit/QTextEdit

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Display strings side by side using QLineEdit/QTextEdit

    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    arunvv (14th February 2008)

  4. #3
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Display strings side by side using QLineEdit/QTextEdit

    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

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Display strings side by side using QLineEdit/QTextEdit

    Just append it to its current text. Get the current text, append new stuff, set new text.
    J-P Nurmi

  6. #5
    Join Date
    Jan 2008
    Location
    Vancouver, Canada
    Posts
    54
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Display strings side by side using QLineEdit/QTextEdit

    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....

    Qt Code:
    1. QString time = "150";
    2. list << time << "s"; //puts the time, 150 as the first item in the list, then s.
    3. list.join(" "); //putting a space in the quotation marks joins the two strings in the list with a space between the entities.
    4. //this string will now look like "150 s"
    To copy to clipboard, switch view to plain text mode 

    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.

  7. #6
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Display strings side by side using QLineEdit/QTextEdit

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.