How to ingore specific image copy in QTextBrowser?



  • I have a ChatView widget based on QTextBrowser, where I put two image anchors to achieve click event. I want copy and paste action to ignore these two items. How can I achieve it?

    target items:
    0_1528338946837_8579bafd-a1a1-4c31-b205-2cb745db57f6-image.png

    select and copy:
    0_1528339054647_7dc24af3-0c3d-483f-851d-7936de3d1d3d-image.png

    paste to a widget based on QTextEdit :
    0_1528339079541_d0cfa37e-746a-4ba9-86d6-1dc1f98b4e47-image.png

    what I want to achieve without any extra editor action:
    0_1528339539593_80eec492-c10a-4f29-8413-1394ee670c4d-image.png



  • Maybe you can reimplement the Clipboard of aplication to ignore these imagens (removing them of plain text).
    But also, you can reimplement the paste action of QTextBrowser class and remove these image of plaintext.

    -> Read More:
    QTextBrowser Members
    Paste Action Documentation
    insert From MineData Documentation


  • Moderators

    @dscyw
    reimplement createMimeDataFromSelection()
    Either you recreate the whole mime-data yourself or you call the base-class implementation and remove the <img> elements from the text/html data.

    Actually you can also completely create your own mime-type and store anything you like in there. Then reimplement insertFromMimeData() and handle your custom mime-type.



  • @KillerSmath @raven-worx Thanks. I will try it and post the result later. I think it's a non-trivial task.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.