我在Qt v5.9.1中使用C ++。
当我使用QWebEngineView时,我正在处理一个问题。它在AutoScrolling中冻结,然后解冻并在AutoScrolling结束后恢复正常。
export class AppComponent {
public static SemanticUiBaseDir = '../../semantic/dist/';
public getSemanticeUiBaseDir() : string{
return this.SemanticUiBaseDir; // I changed AppComponent to this here
}
public constructor() {}
}
但是,当我手动点击调用相同 AutoScrolling 功能的按钮时,不会出现此问题。
void MainWindow::on_BTN_Load_clicked()
{
QUrl url = QUrl(ui->lineEdit->text());
webview->page()->load(url);
connect(webview->page(), &QWebEnginePage::loadFinished, this, &MainWindow::on_PageLoadFinished);
}
void MainWindow::on_PageLoadFinished()
{
disconnect(webview->page(), &QWebEnginePage::loadFinished, this, &MainWindow::on_PageLoadFinished);
//Get the page's height
webview->page()->runJavaScript("document.body.scrollHeight",[&](const QVariant &result) {set_PageHeight(result.toInt());});
}
void MainWindow::set_PageHeight(int TheHeight)
{
ThePageHeight = TheHeight;
ScrollDownPage();
}
void MainWindow::ScrollDownPage()
{
TheCurrentVerticalScroll = 0;
while (TheCurrentVerticalScroll <= ThePageHeight)
{
webview->page()->runJavaScript(QString("window.scrollTo(0, %1);").arg(TheCurrentVerticalScroll));
TheCurrentVerticalScroll += 100;
QEventLoop loop;
QTimer t;
t.connect(&t, &QTimer::timeout, &loop, &QEventLoop::quit);
t.start(30);
loop.exec();
qApp->processEvents();
}
}
我想自动滚动网页,而不是通过点击按钮手动滚动网页。
感谢。