QML TextArea maximum line count



  • 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?



  • 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



  • 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.



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.