×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Regular Contributor
    Join Date
    Nov 2011
    Posts
    104

    Question What is the command used to display the text in a new line?

    Hi,
    I am new to Qt and i tried a application in which i am displaying a page with a paragraph of text.

    Here is my code:

    #include "finddialog.h"
    #include "ui_finddialog.h"
    #include<QtGui>

    finddialog::finddialog(QWidget *parent) :QWidget(parent)
    {
    label = new QLabel(tr( "But soft, what light through yonder window breaks? / "
    "It is the east, and Juliet is the sun. / "
    "Arise, fair sun, and kill the envious moon, /"
    "Who is already sick and pale with grief / "
    "That thou, her maid, art far more fair than she."
    ));

    QHBoxLayout *topLeftLayout = new QHBoxLayout;
    topLeftLayout->addWidget(label);

    QVBoxLayout *leftLayout = new QVBoxLayout;
    leftLayout->addLayout(topLeftLayout);

    QVBoxLayout *rightLayout = new QVBoxLayout;

    // rightLayout->addStretch();
    QHBoxLayout *mainLayout = new QHBoxLayout;
    mainLayout->addLayout(leftLayout);
    mainLayout->addLayout(rightLayout);
    setLayout(mainLayout);
    setFixedHeight(sizeHint().height());
    }
    I am getting the output but i am getting the text in a single line.


    What i need is to display each and every line one by one so can anyone please give the command used to display the text in a new line...



    Regards,
    Harish.

  2. #2
    Super Contributor
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    Re: What is the command used to display the text in a new line?

    Set width of QLabel and then call setWordWrap(TRUE).

  3. #3
    Super Contributor
    Join Date
    Oct 2008
    Location
    INDIA
    Posts
    2,326

    Re: What is the command used to display the text in a new line?

    what about this ?

    Code:
     QLabel *label = new QLabel(this);
     label->setText("first line\nsecond line");
    regards,
    rahul

  4. #4
    Regular Contributor
    Join Date
    Nov 2011
    Posts
    104

    Re: What is the command used to display the text in a new line?

    Thank you Savaj.

  5. #5
    Regular Contributor
    Join Date
    Nov 2011
    Posts
    104

    Re: What is the command used to display the text in a new line?

    Thank You Rahul...

  6. #6
    Super Contributor
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    Re: What is the command used to display the text in a new line?

    Adding "\n" is not a good idea, since size (width) of the screen may not be same on all devices.

Similar Threads

  1. How to read line by line from rich text editor
    By giang1194 in forum Symbian
    Replies: 4
    Last Post: 2011-03-25, 23:04
  2. Replies: 5
    Last Post: 2008-09-23, 09:39
  3. Replies: 7
    Last Post: 2007-05-14, 14:04
  4. Replies: 3
    Last Post: 2004-01-11, 08:01

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×