QWebView<Qt5.5> paste image in clipboard does not work
-
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:'); });
});
-
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).
-
@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! -
@redstoneleo
Just be aware/for anyone reading this: Your solution is doubtless useful/correct, but it is forQWebEngine
. This thread is from a decade ago when that did not exist and is forQWebView
, a different Qt web viewer engine which no longer exists/is supported.