Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    QTextEdit and CR

    General and Desktop
    3
    6
    2027
    Loading More Posts
    • 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.
    • R
      RSFJ last edited by

      I'm having trouble filling a QTextEdit object with a series of numbers, each one of which is to appear on a separate line. For example,

      @
      QString blah;
      for (int i = 1; i < 100; i++)
      {
      blah += QString::number(i);
      blah += tr("\n");
      }

      qDebug() << blah;

      testWidget = new QTextEdit(blah);@

      The call to qDebug() prints just what you would expect: the numbers from 1 to 99, each on a different line. But the QTextEdit object displays the numbers on one long line.

      If it matters, I'm on Windows. The QTextEdit object is display with everything at the default settings.

      I tried various combinations of using (or not) tr() in the hope that it might perform some magic, and I tried "\n", "\n\r", "\r\n" and (just for kicks) "\r". They all do the same thing: the CR and/or LF becomes a space.

      This seems like the sort of thing that must have been discussed umpteen times, but I haven't found anything helpful.

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        tr won't help you here, it's only there for internationalisation purposes.

        The problem lies in the fact that the constructor interprets the string has html.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • R
          RSFJ last edited by

          Assuming that you're not joking about the html, how are you supposed to turn that "feature" off?

          I tried QString::fromLatin1(), fromUtf8(), fromLocal8Bit(), and even the constructor QString(1,'\n'). I get the same result every time. It's a mystery why this problem (and I can't say that I understand what is going on here) hasn't arisen for me before.

          1 Reply Last reply Reply Quote 0
          • R
            RSFJ last edited by

            I understand what you mean now. The QString is where the problem lies. I need to call QTextEdit.setAcceptRichText(false). Thanks.

            1 Reply Last reply Reply Quote 0
            • D
              dbzhang800 last edited by

              You can use setPlainText()

              1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                That, or you have to create a valid html string containing your series of numbers or simply use setPlainText(const QString&)

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post