QWebengine玩转HTML

QWebengine玩转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());
	else
		parentWidget()->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

发布了102 篇原创文章 · 获赞 165 · 访问量 20万+

猜你喜欢

转载自blog.csdn.net/ly305750665/article/details/89230224