1 - This QTextBrowser does it by default when text is appended. When text is inserted it doesn't but it requires very little work:
MyBrowser
::MyBrowser( QWidget* parent
) : atBottom( false )
{
connect( this, SIGNAL( textChanged() ), this, SLOT( scrollToBottom() ) );
connect( this->verticalScrollBar(), SIGNAL( valueChanged( int ) ), this, SLOT( scrolledTo( int ) ) );
}
void MyBrowser::scrollToBottom( void )
{
if( this->atBottom )
{
this->verticalScrollBar()->setValue( this->verticalScrollBar()->maximum() );
}
}
void MyBrowser::scrolledTo( int val )
{
this->atBottom = val == this->verticalScrollBar()->maximum();
}
MyBrowser::MyBrowser( QWidget* parent ) :
QTextBrowser( parent ),
atBottom( false )
{
connect( this, SIGNAL( textChanged() ), this, SLOT( scrollToBottom() ) );
connect( this->verticalScrollBar(), SIGNAL( valueChanged( int ) ), this, SLOT( scrolledTo( int ) ) );
}
void MyBrowser::scrollToBottom( void )
{
if( this->atBottom )
{
this->verticalScrollBar()->setValue( this->verticalScrollBar()->maximum() );
}
}
void MyBrowser::scrolledTo( int val )
{
this->atBottom = val == this->verticalScrollBar()->maximum();
}
To copy to clipboard, switch view to plain text mode
2 - I don't quite get your question. The browser doesn't scroll anywhere when you resize it, just show more/less text.
Bookmarks