Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML TextArea maximum line count

QML TextArea maximum line count

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 4.9k Views
  • 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.
  • Z Offline
    Z Offline
    ZergedU
    wrote on last edited by
    #1

    Hey everyone,

    I have a qml TextArea from QtQuick.Controls (QtQuick 2.7), and I'm trying to set the maximum line count. My program uses the TextArea as the output for a sudo command prompt and I need to limit the number of lines being displayed. If I don't limit the number of lines, the memory usage of my program spikes very quickly.

    I didn't find anything related to setting the maximum number of lines in the documentation TextArea. I do know that I can limit the maximum block count using QTextDocument, and I can expose the underlying QTextDocument with QQuickTextDocument, but there is a disclaimer saying:

    Warning: The QTextDocument provided is used internally by Qt Quick elements to provide text manipulation primitives. You are not allowed to perform any modification of the internal state of the QTextDocument. If you do, the element in question may stop functioning or crash.

    Does anyone have any ideas?

    1 Reply Last reply
    0
    • jpnurmiJ Offline
      jpnurmiJ Offline
      jpnurmi
      wrote on last edited by jpnurmi
      #2

      I'm pretty sure setting a maximum line count via QTextDocument does not conflict with how QQuickTextEdit uses QTextDocument, but I think TextEdit (*) should simply expose the maximum line count as a property. Feel free to file a suggestion. :)

      *) Qt Quick Controls 2 TextArea inherits TextEdit from Qt Quick

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        ZergedU
        wrote on last edited by
        #3

        I was able to set the maximum block count of the underlying QTextDocument using the method described above, but unfortunately it does not work as intended. The QTextDocument documentation says:

        maximumBlockCount : int
        Specifies the maximum number of blocks the document may have. If there are more blocks in the document that specified with this property blocks are removed from the beginning of the document.

        When I tested this with the equivalent QWidget (QTextEdit) it produces the desired result. Every time a line is added after the maximum is reached, 1 line from the beginning is removed. When I tested it with the QML TextArea, some very odd behavior was observed. Instead of adding a new line and removing 1 line from the beginning after the maximum block count (in lines) was reached, it removed 1 line from the beginning without showing the new line that was added. This continued until I added the maximum block count (in lines) again, at which point the text area updated and showed the previously hidden new lines. Then the next line after that was hidden again and the process repeated at intervals of the maximum block count.

        I'm not really sure where to go from here.

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          ZergedU
          wrote on last edited by
          #4

          When I switched from QtQuick.Controls 1.5 to QtQuickControls 2.0 the above issue was resolved and setting the maximumBlockCount of the underlying QTextDocument behaves as expected.

          1 Reply Last reply
          1

          • Login

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