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. textbrower character limit
Qt 6.11 is out! See what's new in the release blog

textbrower character limit

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 5 Posters 1.2k 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.
  • K Offline
    K Offline
    KOHAK
    wrote on last edited by
    #1

    I want to limit the number of characters in the textbrower of pyqt.
    If the number of characters is over, I want to make the old letters disappear.

    jsulmJ JonBJ 2 Replies Last reply
    0
    • K KOHAK

      I want to limit the number of characters in the textbrower of pyqt.
      If the number of characters is over, I want to make the old letters disappear.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @KOHAK You could subclass QTextBrowser and overwrite https://doc.qt.io/qt-5/qtextbrowser.html#keyPressEvent There you can count the number of characters and remove old characters if needed.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      K 1 Reply Last reply
      1
      • K KOHAK

        I want to limit the number of characters in the textbrower of pyqt.
        If the number of characters is over, I want to make the old letters disappear.

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

        @KOHAK
        You could try to see whether a suitable QRegularExpressionValidator stops the user typing more characters than you want to allow.

        Otherwise you must follow @jsulm's approach.

        1 Reply Last reply
        0
        • jsulmJ jsulm

          @KOHAK You could subclass QTextBrowser and overwrite https://doc.qt.io/qt-5/qtextbrowser.html#keyPressEvent There you can count the number of characters and remove old characters if needed.

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

          @jsulm Is it possible to limit the textbrower content even though it is not my input?

          jsulmJ 1 Reply Last reply
          0
          • K KOHAK

            @jsulm Is it possible to limit the textbrower content even though it is not my input?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by jsulm
            #5

            @KOHAK Do you mean if the text is set via https://doc.qt.io/qt-5/qtextedit.html#setText for example? You can do this also if you subclass QTextBrowser and override setText() and the other set*() methods.

            Alternative would be to connect a slot to https://doc.qt.io/qt-5/qtextedit.html#textChanged signal and handle your requirement there.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            3
            • S Offline
              S Offline
              SimonSchroeder
              wrote on last edited by
              #6

              From my experience, these kind of modifications are better done using QTextDocument. Every QTextEdit has an underlying QTextDocument. The document class has a lot more signals/slots you can connect to and control the overall behaviour of the content.

              1 Reply Last reply
              0
              • O Offline
                O Offline
                ollarch
                wrote on last edited by ollarch
                #7

                Hi,

                Could you try this?

                myTextBrowser->document()->setMaximumBlockCount(iMaxValue);
                

                You have to adapt it to Python as it is C++.

                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