Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. New line (\n) doesn't work
Forum Update on Tuesday, May 27th 2025

New line (\n) doesn't work

Scheduled Pinned Locked Moved Solved General and Desktop
qstring
4 Posts 3 Posters 10.8k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gabor53
    wrote on last edited by
    #1

    Hi,
    I try to use the code below in a QMessageBox.

    QString submit_warning;
     submit_warning = submit_warning + "<b><font size='16' color='red'>*Please add a picture of the Friend!\n</b></font>";
    

    The text is displayed nicely, but the new line character is not working. It prints the next warning in the same line.
    Please tell me what I did incorrectly.
    Thank you.

    1 Reply Last reply
    0
    • Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by
      #2

      Going by memory (so I might be wrong)....

      Short version: use a "<br>" instead.

      Long version: QMessageBox::textFormat defaults to Qt::AutoText, which attempts to detect if you're using Qt::PlainText or Qt::RichText. I believe that "\n" works for PlaintText, while "<br>" works for RichText. And I'm guessing, your existing HTML markup (such as "<b>") will cause the detection to choose RichText.

      Cheers.

      K 1 Reply Last reply
      7
      • G Offline
        G Offline
        gabor53
        wrote on last edited by
        #3

        Thank you.

        1 Reply Last reply
        0
        • Paul ColbyP Paul Colby

          Going by memory (so I might be wrong)....

          Short version: use a "<br>" instead.

          Long version: QMessageBox::textFormat defaults to Qt::AutoText, which attempts to detect if you're using Qt::PlainText or Qt::RichText. I believe that "\n" works for PlaintText, while "<br>" works for RichText. And I'm guessing, your existing HTML markup (such as "<b>") will cause the detection to choose RichText.

          Cheers.

          K Offline
          K Offline
          Kophyogyi
          wrote on last edited by
          #4

          @Paul-Colby thank you

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved