本文整理汇总了C++中QWebPage::setViewportSize方法的典型用法代码示例。如果您正苦于以下问题:C++ QWebPage::setViewportSize方法的具体用法?C++ QWebPage::setViewportSize怎么用?C++ QWebPage::setViewportSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QWebPage
的用法示例。
在下文中一共展示了QWebPage::setViewportSize方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: renderPageTo
void Viewer::renderPageTo(QImage* image)
{
QWebPage *page = webView->page();
QWebFrame *frame = page->currentFrame();
QSize origSize = page->viewportSize();
page->setViewportSize(frame->contentsSize());
QPainter painter(image);
frame->render(&painter);
painter.end();
page->setViewportSize(origSize);
}
示例2: createThumbnail
void PageScreen::createThumbnail()
{
QWebPage* page = m_view->page();
const int heightLimit = 20000;
const QPoint originalScrollPosition = page->mainFrame()->scrollPosition();
const QSize &originalSize = page->viewportSize();
const QSize &frameSize = page->mainFrame()->contentsSize();
const int verticalScrollbarSize = page->mainFrame()->scrollBarGeometry(Qt::Vertical).width();
const int horizontalScrollbarSize = page->mainFrame()->scrollBarGeometry(Qt::Horizontal).height();
int yPosition = 0;
bool canScroll = frameSize.height() > heightLimit;
// We will split rendering page into smaller parts to avoid infinite loops
// or crashes.
do {
int remainingHeight = frameSize.height() - yPosition;
if (remainingHeight <= 0) {
break;
}
QSize size(frameSize.width(),
remainingHeight > heightLimit ? heightLimit : remainingHeight);
page->setViewportSize(size);
page->mainFrame()->scroll(0, qMax(0, yPosition - horizontalScrollbarSize));
QImage image(page->viewportSize().width() - verticalScrollbarSize,
page->viewportSize().height() - horizontalScrollbarSize,
QImage::Format_ARGB32_Premultiplied);
QPainter painter(&image);
page->mainFrame()->render(&painter);
painter.end();
m_pageImages.append(image);
canScroll = remainingHeight > heightLimit;
yPosition += size.height();
}
while (canScroll);
page->setViewportSize(originalSize);
page->mainFrame()->setScrollBarValue(Qt::Vertical, originalScrollPosition.y());
page->mainFrame()->setScrollBarValue(Qt::Horizontal, originalScrollPosition.x());
m_imageScaling = new QFutureWatcher<QImage>(this);
m_imageScaling->setFuture(QtConcurrent::run(this, &PageScreen::scaleImage));
connect(m_imageScaling, SIGNAL(finished()), SLOT(showImage()));
}
示例3: createPixmap
void PageScreen::createPixmap()
{
QWebPage* page = m_view->page();
QSize originalSize = page->viewportSize();
page->setViewportSize(page->mainFrame()->contentsSize());
QImage image(page->viewportSize(), QImage::Format_ARGB32);
QPainter painter(&image);
page->mainFrame()->render(&painter);
painter.end();
m_pagePixmap = QPixmap::fromImage(image);
page->setViewportSize(originalSize);
}
示例4: forceRender
void Editor::forceRender(QSize size)
{
QWebPage *page = m_webView->page();
page->setViewportSize(size);
QImage image(size.width(), size.height(), QImage::Format_Mono);
QPainter painter(&image);
page->mainFrame()->render(&painter);
}
示例5: createThumbnail
void PageScreen::createThumbnail()
{
QWebPage* page = m_view->page();
QSize originalSize = page->viewportSize();
page->setViewportSize(page->mainFrame()->contentsSize());
m_pageImage = QImage(page->viewportSize(), QImage::Format_ARGB32_Premultiplied);
QPainter painter(&m_pageImage);
page->mainFrame()->render(&painter);
painter.end();
m_verticalScrollbarSize = page->mainFrame()->scrollBarGeometry(Qt::Vertical).width();
m_horizontalScrollbarSize = page->mainFrame()->scrollBarGeometry(Qt::Horizontal).height();
page->setViewportSize(originalSize);
m_imageScaling = new QFutureWatcher<QImage>(this);
connect(m_imageScaling, SIGNAL(finished()), SLOT(showImage()));
m_imageScaling->setFuture(QtConcurrent::run(this, &PageScreen::scaleImage));
}
示例6: onWebPageOver
void ItemHttpMsg::onWebPageOver(bool bFinished)
{
QWebPage *page = _web->page();
if (page != nullptr)
{
QSize pageSize = page->mainFrame()->contentsSize();
QImage retImage(pageSize, QImage::Format_ARGB32_Premultiplied);
QPainter p(&retImage);
page->setViewportSize(pageSize);
page->mainFrame()->render(&p);
_image = retImage;
update();
}
}
示例7: main
int main(int argc, char* argv[])
{
QWebSettings::globalSettings()->setAttribute(QWebSettings::DnsPrefetchEnabled, true);
QWebSettings::globalSettings()->setAttribute(QWebSettings::JavascriptEnabled, false);
QWebSettings::globalSettings()->setAttribute(QWebSettings::AutoLoadImages, false);
QWebSettings::globalSettings()->setAttribute(QWebSettings::JavaEnabled, false);
QWebSettings::globalSettings()->setAttribute(QWebSettings::AutoLoadImages, false);
QWebSettings::globalSettings()->setDefaultTextEncoding("GB18030-0");
QWebSettings::globalSettings()->setDefaultTextEncoding("GB18030-0");
QWebSettings::globalSettings()->setAttribute(QWebSettings::JavaEnabled, false);
QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, false);
QWebSettings::globalSettings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, false);
QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, false);
QWebSettings::globalSettings()->setAttribute(QWebSettings::PrintElementBackgrounds, false);
QApplication app(argc, argv);
QWebView* view = new QWebView(NULL);
QWebPage* page = view->page();
page->setViewportSize(QSize(947, 843));
QEventLoop loop;
QUrl url("http://www.baidu.com");
if (argc > 1) {
url = QUrl(argv[1]);
}
view->load(url);
QObject::connect(page, SIGNAL(loadFinished(bool)), &loop,
SLOT(quit()));
loop.exec();
QWebFrame * frame = view->page()->mainFrame();
QWebVDom *webvdom = new QWebVDom(frame);
::vdom::Window window;
webvdom->buildVdom(&window);
std::cout << window.Utf8DebugString() << std::endl;
std::cout << "code: " << webvdom->httpStatusCode() << std::flush;
std::cout << "mimetype: " << webvdom->mimeType() << std::endl;
std::cout << "last_modified: " << webvdom->lastModified() << std::endl;
std::cout << "expires: " << webvdom->expires() << std::endl;
std::cout << std::flush;
view->show();
app.exec();
}
示例8: main
int main(int argc, char *argv[])
{
struct sigaction action;
memset(&action, 0, sizeof(struct sigaction));
action.sa_handler = term;
sigaction(SIGTERM, &action, NULL);
int fps = atoi(argv[4]);
int width = atoi(argv[2]);
int height = atoi(argv[3]);
init_shared_data(atoi(argv[2]), atoi(argv[3]));
QApplication app(argc, argv);
QWebPage page;
QPalette palette = page.palette();
palette.setBrush(QPalette::Base, Qt::transparent);
page.setPalette(palette);
page.mainFrame()->setUrl(QUrl::fromUserInput(argv[1]));
page.setViewportSize(QSize(width, height));
page.mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
page.mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
pthread_mutex_lock(&data->mutex);
QImage image(&data->data, width, height, QImage::Format_RGBA8888);
QPainter painter(&image);
pthread_mutex_unlock(&data->mutex);
while (!done) {
app.processEvents();
pthread_mutex_lock(&data->mutex);
image.fill(0);
page.mainFrame()->render(&painter, QWebFrame::ContentsLayer);
pthread_mutex_unlock(&data->mutex);
usleep(1000000 / fps);
}
return 0;
}
示例9: paint
void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
{
Q_UNUSED( itemStyle );
Q_UNUSED( pWidget );
if ( !painter )
{
return;
}
if ( !shouldDrawItem() )
{
return;
}
drawBackground( painter );
painter->save();
//antialiasing on
painter->setRenderHint( QPainter::Antialiasing, true );
double penWidth = hasFrame() ? pen().widthF() : 0;
QRectF painterRect( penWidth + mMargin, penWidth + mMargin, rect().width() - 2 * penWidth - 2 * mMargin, rect().height() - 2 * penWidth - 2 * mMargin );
QString textToDraw = displayText();
if ( mHtmlState )
{
painter->scale( 1.0 / mHtmlUnitsToMM / 10.0, 1.0 / mHtmlUnitsToMM / 10.0 );
QWebPage *webPage = new QWebPage();
webPage->setNetworkAccessManager( QgsNetworkAccessManager::instance() );
//Setup event loop and timeout for rendering html
QEventLoop loop;
QTimer timeoutTimer;
timeoutTimer.setSingleShot( true );
//This makes the background transparent. Found on http://blog.qt.digia.com/blog/2009/06/30/transparent-qwebview-or-qwebpage/
QPalette palette = webPage->palette();
palette.setBrush( QPalette::Base, Qt::transparent );
webPage->setPalette( palette );
//webPage->setAttribute(Qt::WA_OpaquePaintEvent, false); //this does not compile, why ?
webPage->setViewportSize( QSize( painterRect.width() * mHtmlUnitsToMM * 10.0, painterRect.height() * mHtmlUnitsToMM * 10.0 ) );
webPage->mainFrame()->setZoomFactor( 10.0 );
webPage->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff );
webPage->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff );
// QGIS segfaults when rendering web page while in composer if html
// contains images. So if we are not printing the composition, then
// disable image loading
if ( mComposition->plotStyle() != QgsComposition::Print &&
mComposition->plotStyle() != QgsComposition::Postscript )
{
webPage->settings()->setAttribute( QWebSettings::AutoLoadImages, false );
}
//Connect timeout and webpage loadFinished signals to loop
connect( &timeoutTimer, SIGNAL( timeout() ), &loop, SLOT( quit() ) );
connect( webPage, SIGNAL( loadFinished( bool ) ), &loop, SLOT( quit() ) );
//mHtmlLoaded tracks whether the QWebPage has completed loading
//its html contents, set it initially to false. The loadingHtmlFinished slot will
//set this to true after html is loaded.
mHtmlLoaded = false;
connect( webPage, SIGNAL( loadFinished( bool ) ), SLOT( loadingHtmlFinished( bool ) ) );
webPage->mainFrame()->setHtml( textToDraw );
//For very basic html labels with no external assets, the html load will already be
//complete before we even get a chance to start the QEventLoop. Make sure we check
//this before starting the loop
if ( !mHtmlLoaded )
{
// Start a 20 second timeout in case html loading will never complete
timeoutTimer.start( 20000 );
// Pause until html is loaded
loop.exec();
}
webPage->mainFrame()->render( painter );//DELETE WEBPAGE ?
}
else
{
示例10: setViewportSize
void QWebPageProto::setViewportSize(const QSize & size) const
{
QWebPage *item = qscriptvalue_cast<QWebPage*>(thisObject());
if (item)
item->setViewportSize(size);
}