This should work
void MainWindow::changeActivePage(int d32Index) {
if (this->mapTabsToPages.contains(d32Index)) {
if (this->d32CurrentTab > -1) {
Page* pCurPage = this->mapTabsToPages.value(this->d32CurrentTab);
pCurPage->d32ScrollPosition = this->textEdit->verticalScrollBar()->value();
}
Page* pNewPage = this->mapTabsToPages.value(d32Index);
this->textEdit->setPlainText(pNewPage->getText());
this->d32CurrentTab = d32Index;
this->textEdit->verticalScrollBar()->setValue(pNewPage->d32ScrollPosition);
}
}
void MainWindow::changeActivePage(int d32Index) {
if (this->mapTabsToPages.contains(d32Index)) {
if (this->d32CurrentTab > -1) {
Page* pCurPage = this->mapTabsToPages.value(this->d32CurrentTab);
pCurPage->d32ScrollPosition = this->textEdit->verticalScrollBar()->value();
}
Page* pNewPage = this->mapTabsToPages.value(d32Index);
this->textEdit->setPlainText(pNewPage->getText());
this->d32CurrentTab = d32Index;
this->textEdit->verticalScrollBar()->setValue(pNewPage->d32ScrollPosition);
}
}
To copy to clipboard, switch view to plain text mode
I see another problem in the code (may be you are aware of this). When page (tab) is changed, then content (modifications) are lost, and this change in the test content will make the scroll bars maximum value change, and may cause unexpected behaviour. So the suggested code will work for un-modified text / properly saved data only
Bookmarks