linuxsong
21st September 2010, 16:04
I had a question, see these code first:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.resize(500,500);
QPlainTextEdit *text = new QPlainTextEdit(&w);
QString str;
for (int i = 0; i < 50; i++) {
str += "text text text\n";
}
text->setGeometry(QRect(30,30, 200,200));
text->setPlainText(str);
qDebug() << "minimum: " << text->verticalScrollBar()->minimum();
qDebug() << "maximum" << text->verticalScrollBar()->maximum();
qDebug() << text->verticalScrollBar()->value();
text->verticalScrollBar()->setValue(30);
qDebug() << "show before value:" << text->verticalScrollBar()->value();
w.show();
qDebug() << "show after value:" << text->verticalScrollBar()->value();
return a.exec();
}
The output result is :
minimum: 0
maximum 50
0
show before value: 30
show after value: 0
So, why the text->verticalScrollBar()->value() changed after the window show() ?
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.resize(500,500);
QPlainTextEdit *text = new QPlainTextEdit(&w);
QString str;
for (int i = 0; i < 50; i++) {
str += "text text text\n";
}
text->setGeometry(QRect(30,30, 200,200));
text->setPlainText(str);
qDebug() << "minimum: " << text->verticalScrollBar()->minimum();
qDebug() << "maximum" << text->verticalScrollBar()->maximum();
qDebug() << text->verticalScrollBar()->value();
text->verticalScrollBar()->setValue(30);
qDebug() << "show before value:" << text->verticalScrollBar()->value();
w.show();
qDebug() << "show after value:" << text->verticalScrollBar()->value();
return a.exec();
}
The output result is :
minimum: 0
maximum 50
0
show before value: 30
show after value: 0
So, why the text->verticalScrollBar()->value() changed after the window show() ?