1
QTextEdit *editor = new QTextEdit(this);
1
connect(editor->document(),SIGNAL(contentsChanged()),this,SLOT(textAreaChanged()));
1
2
3
4
5
6
7
8
9
10
11
12
13
14
private slots:
void textAreaChanged(){
QTextDocument *document=qobject_cast<QTextDocument*>(sender());
document->adjustSize();
if(document){
QTextEdit *editor=qobject_cast<QTextEdit*>(document->parent()->parent());
if (editor){
int newheight = document->size().rheight()+10;
if (newheight != editor->height()){
editor->setFixedHeight(newheight);
}
}
}
}