Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How can I get/set the max length of a QPlainTextEdit ?
Qt 6.12 LTS is out! See what's new in the release blog

How can I get/set the max length of a QPlainTextEdit ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 4.3k 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.
  • GuerrianG Offline
    GuerrianG Offline
    Guerrian
    wrote on last edited by
    #1

    I know that a similar question about QTextEdit was answered in the technical FAQ, but some of the links in that answer are broken:

    https://wiki.qt.io/Technical_FAQ#How_can_I_get.2Fset_the_max_length_of_a_QTextEdit_.3F

    Linux Mint 18.3
    Qt 5.14.1
    Qt Creator 4.11.1

    1 Reply Last reply
    1
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      I don't see why this answer should not apply to QPlainTextEdit too ... the contentChanged signal is textChanged there but the way is the same.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        The links have been fixed.

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

        GuerrianG 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          The links have been fixed.

          GuerrianG Offline
          GuerrianG Offline
          Guerrian
          wrote on last edited by
          #4

          @Christian-Ehrlicher
          I was wondering about the signal.

          @SGaist
          Thanks to you both!

          Linux Mint 18.3
          Qt 5.14.1
          Qt Creator 4.11.1

          1 Reply Last reply
          0
          • GuerrianG Offline
            GuerrianG Offline
            Guerrian
            wrote on last edited by
            #5

            The compiler doesn't like the signal:

            connect(ui->textEdit, SIGNAL(keyPressEvent(QKeyEvent *)), this, SLOT(keyPress(QKeyEvent *)));

            It says:

            QObject::connect: No such signal QPlainTextEdit::keyPressEvent(QKeyEvent *) in ../MyApp/mainwindow.cpp:40
            QObject::connect: (sender name: 'textEdit')
            QObject::connect: (receiver name: 'MainWindow')

            Linux Mint 18.3
            Qt 5.14.1
            Qt Creator 4.11.1

            1 Reply Last reply
            0
            • GuerrianG Offline
              GuerrianG Offline
              Guerrian
              wrote on last edited by
              #6

              I didn't need this in the end. I used QLineEdit instead of QPlainTextEdit.

              Linux Mint 18.3
              Qt 5.14.1
              Qt Creator 4.11.1

              mrjjM 1 Reply Last reply
              0
              • GuerrianG Guerrian

                I didn't need this in the end. I used QLineEdit instead of QPlainTextEdit.

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Guerrian
                Just for info
                keyPressEvent is not a SIGNAl. its a virtual function and
                can only be altered via subclassing the widget.

                So the links wanted you to override via a subclass and then
                make keypress ignore normal keys when max length was reached.
                Its not possible with SIGNALS alone.

                1 Reply Last reply
                2

                • Login

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