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. How to insert rows one by one in QTextedit.
Forum Updated to NodeBB v4.3 + New Features

How to insert rows one by one in QTextedit.

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 1.5k Views 1 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.
  • A Offline
    A Offline
    Anton Shelenkov
    wrote on last edited by Anton Shelenkov
    #1

    I have a QTextEdit and 2 QStringLists( L1 and L2 ) with numbers.

    I want get this:

    L1[0] L1[1] L1[2] L1[3]
    L2[0] L2[2] L2[2] L2[3]
    L1[4] L1[5] L1[6] L1[7]
    L2[4] L2[5] L2[6] L2[7]

    JonBJ 1 Reply Last reply
    0
    • A Anton Shelenkov

      I have a QTextEdit and 2 QStringLists( L1 and L2 ) with numbers.

      I want get this:

      L1[0] L1[1] L1[2] L1[3]
      L2[0] L2[2] L2[2] L2[3]
      L1[4] L1[5] L1[6] L1[7]
      L2[4] L2[5] L2[6] L2[7]

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Anton-Shelenkov
      So print out your desired numbers in an appropriate loops (probably 4 of them), and send a newline (\n) at the end of each row to break them into lines. (Use http://doc.qt.io/qt-5/qtextedit.html#setPlainText and/or http://doc.qt.io/qt-5/qtextedit.html#append) What's the issue with QTextEdit otherwise?

      A 1 Reply Last reply
      0
      • JonBJ JonB

        @Anton-Shelenkov
        So print out your desired numbers in an appropriate loops (probably 4 of them), and send a newline (\n) at the end of each row to break them into lines. (Use http://doc.qt.io/qt-5/qtextedit.html#setPlainText and/or http://doc.qt.io/qt-5/qtextedit.html#append) What's the issue with QTextEdit otherwise?

        A Offline
        A Offline
        Anton Shelenkov
        wrote on last edited by
        #3

        @JonB
        I wrote not exactly. I need to fill the line completely, depending on the size of the TextEdit. (If the screen is wide, then all 18 numbers are relevant in the line, and if narrow then 4 will have to be written in new lines). I hope so I understood more clearly.

        I do not understand how to get the size of a string of text edita or check whether the end of line is reached..

        JonBJ 1 Reply Last reply
        0
        • A Anton Shelenkov

          @JonB
          I wrote not exactly. I need to fill the line completely, depending on the size of the TextEdit. (If the screen is wide, then all 18 numbers are relevant in the line, and if narrow then 4 will have to be written in new lines). I hope so I understood more clearly.

          I do not understand how to get the size of a string of text edita or check whether the end of line is reached..

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Anton-Shelenkov
          Hopefully you will not need to do that. See http://doc.qt.io/qt-5/qtextedit.html#LineWrapMode-enum. Isn't setLineWrapMode(QTextEdit::WidgetWidth) what you are wanting?

          A 1 Reply Last reply
          2
          • JonBJ JonB

            @Anton-Shelenkov
            Hopefully you will not need to do that. See http://doc.qt.io/qt-5/qtextedit.html#LineWrapMode-enum. Isn't setLineWrapMode(QTextEdit::WidgetWidth) what you are wanting?

            A Offline
            A Offline
            Anton Shelenkov
            wrote on last edited by
            #5

            @JonB Thanks for answer, but in my case it's not correct solution.

            I know solution, but i don't know how check "endl" in text edit.

            JonBJ 1 Reply Last reply
            0
            • A Anton Shelenkov

              @JonB Thanks for answer, but in my case it's not correct solution.

              I know solution, but i don't know how check "endl" in text edit.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @Anton-Shelenkov said in How to insert rows one by one in QTextedit.:

              but i don't know how check "endl" in text edit.

              Sorry, no idea what this means.

              1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #7

                Hi
                If you mean you want to make the word wrapping yourself, and need to know the pixel width of random text, it goes something like

                QFont myFont(fontName, fontSize);;
                QString str("I wonder how wide this is?");
                
                QFontMetrics fm(myFont);
                int width=fm.width(str);
                

                But you would have to use the font , that TextEdit will use for that paragraph when it draws it.
                If you only use the default font for all paragraphs, your should be able to do something
                QPlainTextEdit monoEdit;
                QTextDocument *doc = monoEdit.document();
                QFont font = doc->defaultFont();

                A 1 Reply Last reply
                2
                • mrjjM mrjj

                  Hi
                  If you mean you want to make the word wrapping yourself, and need to know the pixel width of random text, it goes something like

                  QFont myFont(fontName, fontSize);;
                  QString str("I wonder how wide this is?");
                  
                  QFontMetrics fm(myFont);
                  int width=fm.width(str);
                  

                  But you would have to use the font , that TextEdit will use for that paragraph when it draws it.
                  If you only use the default font for all paragraphs, your should be able to do something
                  QPlainTextEdit monoEdit;
                  QTextDocument *doc = monoEdit.document();
                  QFont font = doc->defaultFont();

                  A Offline
                  A Offline
                  Anton Shelenkov
                  wrote on last edited by
                  #8

                  @mrjj Thanks.

                  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