谢谢大家看到:当Dialog有hide时,QPixmap是空的,为什么???而且这种方式效率太低...帮帮我
问问题
73 次
1 回答
0
、、、
#include "webKitDialog.h"
#include "ui_webKitDialog.h"
#include <QWebEngineView>
#include <QWebEnginePage>
#include "HiWebEnginePage.h"
#include <QTimer>
#include <QThread>
#include <QScreen>
#include <QGuiApplication>
#include <QPixmap>
webKitDialog::webKitDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::webKitDialog)
{
ui->setupUi(this);
m_view = new QWebEngineView(this);
m_page = new HiWebEnginePage(m_view);
m_view->setPage(m_page);
ui->lineEdit->setText("http://www.youku.com");
ui->verticalLayout->addWidget(m_view, 1);
on_lineEdit_editingFinished();
QTimer *time = new QTimer;
connect(time, &QTimer::timeout, this, &webKitDialog::onTimeOut);
//
time->start(1000);
}
webKitDialog::~webKitDialog()
{
delete ui;
}
void webKitDialog::showEvent(QShowEvent *event)
{
m_view->reload();
m_view->show();
QDialog::showEvent(event);
}
void webKitDialog::onTimeOut()
{
emit onImageUpdate(createThumbnail(m_view->size()));
}
void webKitDialog::on_pushButton_close_clicked()
{
this->hide();
m_view->showNormal();
}
void webKitDialog::on_pushButton_max_clicked()
{
qreal factor = m_view->zoomFactor();
factor += 0.25;
if(factor > 5)
{
factor = 5;
}
m_page->setZoomFactor(factor);
}
void webKitDialog::on_pushButton_refresh_clicked()
{
m_view->reload();
}
void webKitDialog::on_lineEdit_editingFinished()
{
QString strUrl = ui->lineEdit->text();
m_page->load(QUrl(strUrl));
}
void webKitDialog::on_pushButton_zoonout_clicked()
{
qreal factor = m_view->zoomFactor();
factor -= 0.25;
if(factor < 0.25)
{
factor = 0.25;
}
m_page->setZoomFactor(factor);
}
QPixmap webKitDialog::createThumbnail(const QSize &size)
{
QPixmap pixMap(size);
qDebug() << "size" << size << endl;
QRegion rg(0, 0, size.width(), size.height());
QPainter painter(&pixMap);
m_view->page()->view()->render(&painter, QPoint(), rg);
painter.end();
return pixMap;
}
、、、</p>
于 2020-04-21T11:14:11.087 回答