Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. QWebView<Qt5.5> paste image in clipboard does not work

QWebView<Qt5.5> paste image in clipboard does not work

Scheduled Pinned Locked Moved Unsolved Qt WebKit
4 Posts 4 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Enmaai
    wrote on last edited by
    #1

    i add a WYSIWYG HTML Editor ,but paste not work,the same work in chrome 、firefox,etc..

    you can visit this test http://summernote.org/
    my code follow:

    ui->webView->settings()->setDefaultTextEncoding("utf-8");
    ui->webView->settings()->globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
    ui->webView->settings()->globalSettings()->setAttribute(QWebSettings::JavaEnabled, true);
    ui->webView->settings()->globalSettings()->setAttribute(QWebSettings::JavascriptCanAccessClipboard, true);
    ui->webView->settings()->globalSettings()->setAttribute(QWebSettings::LocalStorageEnabled, true);

    ---------------html is-----------------
    $inputbox.on('paste',function(event){
    var clipboardData;
    if(event.clipboardData)
    {
    clipboardData = event.clipboardData;
    }
    if(event.originalEvent.clipboardData)
    {
    clipboardData = event.originalEvent.clipboardData;
    }
    var items;
    if(clipboardData)
    {

    //here error,clipboardData no property named items
    items = clipboardData.items;
    }
    var tt = items[0].getAsFile();

    debug('file is ok:');
    
    readFileAsDataURL(tt).then(function (sDataURL) {
    	debug('read is ok:'+sDataURL);
    	$('<img>').appendTo(document.body)
        .attr('src', sDataURL);
      }).fail(function () {
    	  debug('read is failed:');
      });
    

    });

    1 Reply Last reply
    0
    • T Offline
      T Offline
      ThatDud3
      wrote on last edited by ThatDud3
      #2

      You can get the clipboard data in WebKit, but only during a paste event, for security reasons (random websites being able to copy from your system clipboard at any time would be bad).

      http://stackoverflow.com/questions/10258102/is-there-a-non-flash-way-to-set-get-the-clipboard-data-in-webkit

      1 Reply Last reply
      0
      • R Offline
        R Offline
        redstoneleo
        wrote on last edited by redstoneleo
        #3

        @Enmaai said in QWebView<Qt5.5> paste image in clipboard does not work:

        JavascriptCanAccessClipboard

        You should enable self.settings().setAttribute(QWebEngineSettings.WebAttribute.JavascriptCanAccessClipboard, True) self.settings().setAttribute(QWebEngineSettings.WebAttribute.JavascriptCanPaste, True) to make it work!

        JonBJ 1 Reply Last reply
        0
        • R redstoneleo

          @Enmaai said in QWebView<Qt5.5> paste image in clipboard does not work:

          JavascriptCanAccessClipboard

          You should enable self.settings().setAttribute(QWebEngineSettings.WebAttribute.JavascriptCanAccessClipboard, True) self.settings().setAttribute(QWebEngineSettings.WebAttribute.JavascriptCanPaste, True) to make it work!

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @redstoneleo
          Just be aware/for anyone reading this: Your solution is doubtless useful/correct, but it is for QWebEngine. This thread is from a decade ago when that did not exist and is for QWebView, a different Qt web viewer engine which no longer exists/is supported.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved