首页 > Web开发 > 详细

Qt5.WebView.添加节点的测试代码

时间:2018-08-15 10:02:10      阅读:201      评论:0      收藏:0      [点我收藏+]

1、代码:

#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QWebFrame>
#include <QWebElement>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pbtnOpenSVG_clicked()
{
    ui->webView->load(QUrl::fromLocalFile("D:\\DRGIS\\BIN\\PwDrawSvg\\NewSvg.svg"));
}

void PatchElement(void *_p)
{
#ifndef DEBUG_ZZ
    _asm
    {
        push eax
        mov eax,_p
        mov eax,[eax+4]
        or [eax+0xc],0x10
        pop eax
    }
#else// DEBUG_ZZ
    _asm
    {
        push eax
        mov eax,_p
        mov eax,[eax+4]
        or [eax+0x14],0x10
        pop eax
    }
#endif// DEBUG_ZZ
}

void PatchElementUn(void *_p)
{
#ifndef DEBUG_ZZ
    _asm
    {
        push eax
        mov eax,_p
        mov eax,[eax+4]
        and [eax+0xc],0xFFFFFFEF
        pop eax
    }
#else// DEBUG_ZZ
    _asm
    {
        push eax
        mov eax,_p
        mov eax,[eax+4]
        and [eax+0x14],0xFFFFFFEF
        pop eax
    }
#endif// DEBUG_ZZ
}

void MainWindow::on_pbtnAppendWebEle_clicked()
{
    QWebElement eleSvg = ui->webView->page()->currentFrame()->documentElement();
    //qDebug() << eleSvg.tagName();


    QWebElement eleFind = eleSvg.findFirst("#Term_Layer");
    if (eleFind.isNull())
        qDebug() << "eleFind is Null";
    else
        qDebug() << "eleFind is not Null";
    QString str = "<g id=\"zzz\"></g>";

  // ZC: 下面的 PatchElement()和PatchElementUn(),暂时是在 Release中使用,Debug中不确定一定OK... PatchElement(
&eleFind);  // ZC: 使用QWebElement::???Inside(...)的时候,就要对 那个节点 进行Patch ! ! ! eleFind.appendInside(str); PatchElementUn(&eleFind); PatchElement(&eleFind.parent());  // ZC: 使用QWebElement::???Outside(...)的时候,就要对 那个节点的父节点 进行Patch ! ! ! eleFind.appendOutside(str); PatchElementUn(&eleFind.parent()); } void MainWindow::on_pbtnPrintSvgContent_clicked() { qDebug() << ui->webView->page()->currentFrame()->toHtml(); }

2、

#-------------------------------------------------
#
# Project created by QtCreator 2018-08-15T09:00:45
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets                                         webkit                                          webkitwidgets

TARGET = WebView_Test_01
TEMPLATE = app


SOURCES += main.cpp        mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

3、

技术分享图片

 

4、

5、

 

Qt5.WebView.添加节点的测试代码

原文:https://www.cnblogs.com/cppskill/p/9479596.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!