QWebengine玩转HTML

编程入门 行业动态 更新时间:2024-10-12 14:17:01

QWebengine<a href=https://www.elefans.com/category/jswz/34/1768105.html style=玩转HTML"/>

QWebengine玩转HTML

QWebengine玩转HTML

文章目录

      • QWebengine玩转HTML
      • 简述
      • 效果图
        • HTML滚动条样式修改
        • 代码
      • 工程文件
      • 结尾

简述

发现Qt一新大陆,以下Jequery控制,更多好玩的好看的效果大家修改,玩耍,嗨皮!

效果图

HTML滚动条样式修改

代码
QString readFiledata(const QString& filepath)
{QFile file;file.setFileName(filepath);file.open(QIODevice::ReadOnly);QString data = file.readAll();file.close();return data;
}void WebView::initControl()
{qputenv("QTWEBENGINE_REMOTE_DEBUGGING", "9223");m_jQuery = readFiledata(":/WebenginePlay/Resources/jquery.min.js");m_jQuery.append("\nvar qt = { 'jQuery': jQuery.noConflict(true) };");connect(this, SIGNAL(titleChanged(QString)), SLOT(adjustTitle()));connect(this, SIGNAL(loadProgress(int)), SLOT(setProgress(int)));connect(this, SIGNAL(loadFinished(bool)), SLOT(finishLoading(bool)));
}void WebView::loadUrl(QUrl url)
{this->load(url);
}void WebView::adjustTitle()
{if (m_progress <= 0 || m_progress >= 100)parentWidget()->setWindowTitle(this->title());elseparentWidget()->setWindowTitle(QString("%1 (%2%)").arg(this->title()).arg(m_progress));
}void WebView::setProgress(int p)
{m_progress = p;adjustTitle();
}void WebView::finishLoading(bool)
{m_progress = 100;adjustTitle();QString code = "qt.jQuery('<link>').attr({ rel: \"stylesheet\",type: \"text/css\",href: \"qrc:/WebenginePlay/Resources/rotate.css\"}).appendTo(\"head\"); undefined";m_jQuery.append("\n");m_jQuery.append(code);page()->runJavaScript(m_jQuery);
}void WebView::highlightAllLinks()
{QString code = "qt.jQuery('a').each( function () { qt.jQuery(this).css('background-color', 'yellow') } ); undefined";this->page()->runJavaScript(code);
}void WebView::rotateImages()
{QString code = "qt.jQuery('img').addClass(\"header\");";this->page()->runJavaScript(code);
}void WebView::removeGifImages()
{QString code = "qt.jQuery('[src*=gif]').remove()";this->page()->runJavaScript(code);
}void WebView::updateScrollerStyle()
{QString code = "qt.jQuery('body').each( function () { qt.jQuery(this).css('background', 'rgba(200,200,200,100)') } ); undefined";this->page()->runJavaScript(code);
}

工程文件

Qt交流大会 853086607 (1元群,用于后期升级群费用)

结尾

不定期上传新作品,解答群中作品相关问题。相关外,能解答则解答。欢迎大家一起探索Qt世界!相关工程,可以联系博主雨田哥:3246214072

更多推荐

QWebengine玩转HTML

本文发布于:2024-02-06 13:00:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1748956.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:玩转   QWebengine   HTML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!