QT4 QgraphicsView not repainting in a "for cycle" of displaying many pages
I wrote a program to experiment with poppler pdf library. I am able to display pdf pages into a graphicsView with a method:
void MainWindow::setPage(int newpage)
{
pdfPage = document->page(newpage);
if (pdfPage == 0) {
// ... error message ...
return;
}
// Generate a QImage of the rendered page
image = pdfPage开发者_运维百科->renderToImage(100.0,100.0,0,0,pdfPage->pageSize().width(),pdfPage->pageSize().height());
if (image.isNull()) {
// ... error message ...
return;
}
pixmap=QPixmap::fromImage(image);
scene->clear();
scene->addPixmap(pixmap);
this->ui->graphicsView->setScene(scene);
this->ui->graphicsView->repaint(); //the same with show(), invalidate scene()
// after the usage, the page must be deleted
delete pdfPage;
}
with single call or in a slot for a control but if I write a cycle like for (i=0;i<200;i++) { setPage(i);} nothing is displayed until the cycle gets to its end, and then just the last page is visible. What's wrong? I tried with msleep(500) in a custom thread class, and tried also calling paintEvent for graphicsView. Can help?
You cannot cause a widget to redraw itself in a loop. In order for a widget (or graphics item) to draw itself, control must return to the event loop every time the appearance of the widget changes. Please see this question and its answers for more information.
精彩评论