3
votes

I'm having problems with QLabel and QScrollArea. I'm trying to make QScrollArea to scroll automatically, but can't find any information about it..

Firstly, I'm using QLabel inside QScrollArea, then QLineEdit outside from QScrollArea. When I type text in QLineEdit, it writes to QLabel and the new line. Whenever it reaches to end of area, QScrollArea doesn't scroll automatically.. How can I do that?

Thank you.

2

2 Answers

2
votes

Can't you use QLineEdit itself instead of Qlabel(if u are using only text)?, so that you dont have to use QScrollArea also.

[edit] What if you set the verticalSlider position to Label->height()

void MainWindow::on_lineEdit_returnPressed() 
{ 
  ui->label->setText(ui->label->text() + ui->lineEdit->text() + "\n"); 

  ui->ScrollArea->verticalScrollBar()->setSliderPosition(label->height())

}
0
votes

Take a look at this example: http://qt-project.org/forums/viewthread/23790/ Without to see your code that is difficult to be more precise ...

[EDITED] Try this:

void MainWindow::on_lineEdit_returnPressed() 
{ 
  ui->label->setText(ui->label->text() + ui->lineEdit->text() + "\n"); 

  ui->lineEdit->moveCursor (QTextCursor::Start) ;
  ui->lineEdit->ensureCursorVisible() ;

  ...
}