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


    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、

  • 相关阅读:
    命保住了!五年时间,我们也搞了一个技术中台(转)
    为什么要前后端分离?有什么优缺点?(转)
    Java WebService _CXF、Xfire、AXIS2、AXIS1_四种发布方式(优缺点对比)
    Java WebService _CXF、Xfire、AXIS2、AXIS1_四种发布方式(使用整理)
    Java WebService(实战) 简单实例
    Intellij IDEA svn的使用记录
    IDEA SonarLint安装及使用
    Java开发中的23种设计模式详解(收藏-转)
    Java中的static关键字解析
    触发器_实现ORACEL自动增长字段
  • 原文地址:https://www.cnblogs.com/cppskill/p/9479596.html
Copyright © 2020-2023  润新知