I’ve got a QPrintPreviewWidget, I update its content programmatically based on user input. The problem when doing so is that the scrollbar stays where it was, while I need it to go back to the top.
I tried using the scroll function with a very big number but that didn’t do anything. Any suggestion?
Edit:
Here is the structure of the dialog in Qt Creator:

Then I add the QPrintPreviewWidget to the previewWidgetContainter layout using this code:
previewWidget_ = new QPrintPreviewWidget(printer_, this);
previewWidget_->fitToWidth();
ui->previewWidgetContainter->addWidget(previewWidget_);
Edit:
I followed @tmpearce ‘s suggestion, but that didn’t work. On the showEvent I set the current page but it has no effect whatsoever. My code is something like this:
qDebug() << "Before" << previewWidget.currentPage();
previewWidget.setCurrentPage(0);
qDebug() << "After" << previewWidget.currentPage();
And the output of this is always something like that:
Before 15
After 15
I also tried setting the page in various other places but the result is always the same. That looks like a bug in QPrintPreviewWidget so I’m going to give up for now. Thanks anyway for the suggestions.
Without knowing more about the specifics of your code, my suggestion would be to explicitly call this slot:
QPrintPreviewWidget::setCurrentPage(int)after changing the contents of the widget.