Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QWebEnginePage- copy images and text to clipboard?



  • I've got a PyQt5 app which uses a QtWebEngineView to display a programmatically generated bit of HTML, which includes a large number of image thumbnails and accompanying text notes.

    The users want to be able to select a section of the output to the clipboard, so that that section can be pasted into a program like Word or Outlook.

    When the programmatically generated HTML is opened in a browser like Chrome, selecting the relevant part and then pasting it works as expected, and the images appear.

    However in the QtWebEngineView, triggering the copy action will copy the text, but not the images, which show as empty space. This is true when the user selects and presses Ctrl+C, and it's also the case when I call .triggerAction(QWebEnginePage.Copy) on the QWebEnginePage.

    Does QtWebEngineView supporting copyinig images to the clipboard the same way that Chrome does? If so, how would I access this ability?



  • @donquibeats
    Does triggerAction(QWebEnginePage.CopyImageToClipboard) work?



  • @JonB Thanks for the response.
    .copyImageToClipboard doesn't work in this case. The user selection spans several HTML items including text and images, so when more than just a single image is selected, it doesn't give the desired result.



  • I should add that .triggerAction(QWebEnginePage.Copy) almost does what's wanted. It copies the area of the HTML that the user has selected, and this can be pasted. The only problem is that any images that are within that selection disappear when pasted into another program or document.


Log in to reply