FOX Community

Recent site activity

Cookbook‎ > ‎

Autoscroll FXText when text gets added

Problem

You're dynamically adding text to the end of the buffer in an FXText widget and you'd like for the text to automatically scroll up so that the newly added text is always visible.

Solution

Call makePositionVisible(pos), where pos is the text offset (in characters) that you want to reveal. For this case, you probably want to pass the beginning of the last row; here's an example:

// Add some text to the end of the buffer
textWidget->appendText("Line 1\n");
textWidget->appendText("Line 2\n");
textWidget->appendText("Line 3\n");

// The length of the buffer tells us the position of the last character in the document
FXint lastPos = textWidget->getLength();

// Use rowStart() to find the position of the start of the row
FXint lastRowStartPos = textWidget->rowStart(lastPos);

// Make that position visible
textWidget->makePositionVisible(lastRowStartPos);

Contribution(s)

Lyle Johnson