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. QPlainTextEdit - Multiline edit box
Forum Updated to NodeBB v4.3 + New Features

QPlainTextEdit - Multiline edit box

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.0k 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.
  • S Offline
    S Offline
    stretchthebits
    wrote on last edited by
    #1

    Allo,
    How can I change the line spacing for QPlainTextEdit?
    I find that the line spacing is too much.

    JonBJ 1 Reply Last reply
    0
    • S stretchthebits

      Allo,
      How can I change the line spacing for QPlainTextEdit?
      I find that the line spacing is too much.

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

      @stretchthebits
      Did you look through the following:
      https://stackoverflow.com/questions/10317845/qplaintextedit-line-spacing
      https://stackoverflow.com/questions/10250533/set-line-spacing-in-qtextedit
      https://forum.qt.io/topic/109328/qplaintextedit-with-equal-line-heights

      S 1 Reply Last reply
      2
      • JonBJ JonB

        @stretchthebits
        Did you look through the following:
        https://stackoverflow.com/questions/10317845/qplaintextedit-line-spacing
        https://stackoverflow.com/questions/10250533/set-line-spacing-in-qtextedit
        https://forum.qt.io/topic/109328/qplaintextedit-with-equal-line-heights

        S Offline
        S Offline
        stretchthebits
        wrote on last edited by
        #3

        @JonB I looked at the 3 links and to be honest, I am lost.
        For example:
        https://stackoverflow.com/questions/10317845/qplaintextedit-line-spacing

        Is there an example as to how to use QTextBlockFormat?

        I have never been able to figure out how to use a class from the documents at
        https://doc.qt.io/qt-5/qtextblockformat.html

        If I know how to use a class and I just want to change the color or size or something, then those pages are useful since they somewhat explain how to use a member function.

        Please keep in mind that we are not all equal.
        Perhaps you have the skills to not know anything about Qt, and read those docs and write a full program. I don’t.
        I started to learn Qt by looking at the various sample projects that came with Qt Creator.

        JonBJ 1 Reply Last reply
        0
        • S stretchthebits

          @JonB I looked at the 3 links and to be honest, I am lost.
          For example:
          https://stackoverflow.com/questions/10317845/qplaintextedit-line-spacing

          Is there an example as to how to use QTextBlockFormat?

          I have never been able to figure out how to use a class from the documents at
          https://doc.qt.io/qt-5/qtextblockformat.html

          If I know how to use a class and I just want to change the color or size or something, then those pages are useful since they somewhat explain how to use a member function.

          Please keep in mind that we are not all equal.
          Perhaps you have the skills to not know anything about Qt, and read those docs and write a full program. I don’t.
          I started to learn Qt by looking at the various sample projects that came with Qt Creator.

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

          @stretchthebits said in QPlainTextEdit - Multiline edit box:

          Is there an example as to how to use QTextBlockFormat?

          Did you progress to the second link which has a code block showing the usage of QTextBlockFormat? Did you try that out? Or the third one, which also has examples using QTextBlockFormat?

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

            Hi

            If you change your QPlainTextEdit to a QTextEdit.
            (you can right click it in Designer , use the morph menu)

            Then the following code will set line-height to 10

            void MainWindow::on_pushButton_4_released()
            {
            QTextEdit * te = ui->textEdit;
            // get a cursor for selection
            QTextCursor cursor = te->textCursor();
            // select all
            cursor.select(QTextCursor::Document);
            // declare a Block
            QTextBlockFormat fmt;
            //set wanted line height. YTou might want to use fmt.lineHeight() to get current value
            fmt.setLineHeight(10, QTextBlockFormat::FixedHeight);
            // set the format. if you have other formatting, you might want to use mergeformat()
            cursor.setBlockFormat(fmt);
            }

            S 1 Reply Last reply
            0
            • mrjjM mrjj

              Hi

              If you change your QPlainTextEdit to a QTextEdit.
              (you can right click it in Designer , use the morph menu)

              Then the following code will set line-height to 10

              void MainWindow::on_pushButton_4_released()
              {
              QTextEdit * te = ui->textEdit;
              // get a cursor for selection
              QTextCursor cursor = te->textCursor();
              // select all
              cursor.select(QTextCursor::Document);
              // declare a Block
              QTextBlockFormat fmt;
              //set wanted line height. YTou might want to use fmt.lineHeight() to get current value
              fmt.setLineHeight(10, QTextBlockFormat::FixedHeight);
              // set the format. if you have other formatting, you might want to use mergeformat()
              cursor.setBlockFormat(fmt);
              }

              S Offline
              S Offline
              stretchthebits
              wrote on last edited by
              #6

              @mrjj said in QPlainTextEdit - Multiline edit box:

              Hi

              If you change your QPlainTextEdit to a QTextEdit.
              (you can right click it in Designer , use the morph menu)

              Then the following code will set line-height to 10

              void MainWindow::on_pushButton_4_released()
              {
              QTextEdit * te = ui->textEdit;
              // get a cursor for selection
              QTextCursor cursor = te->textCursor();
              // select all
              cursor.select(QTextCursor::Document);
              // declare a Block
              QTextBlockFormat fmt;
              //set wanted line height. YTou might want to use fmt.lineHeight() to get current value
              fmt.setLineHeight(10, QTextBlockFormat::FixedHeight);
              // set the format. if you have other formatting, you might want to use mergeformat()
              cursor.setBlockFormat(fmt);
              }

              Thanks. That seems to work. I just need to give control for the line spacing to the user now.

              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