PDA

View Full Version : QClipboard



Qiieha
18th December 2012, 17:22
Hi,
I have subclassed a QTextEdit, which presents html. If there is a paste from a different application, plaintext should be inserted
and if there is a paste from within the application, the normal html should be inserted.

Maybe you know, how I can notice if there is an intern paste or an extern?

thank you

Zlatomir
18th December 2012, 18:16
I'm not sure that i understand you, are you trying to paste html if the copy command was made on your QTextEdit derived widget (or your application) and plain text if the copy was made from a different application?
A simple answer is to catch copy (Ctrl+C) on your textEdit and make a copy of the string from clipboard and on paste you can compare the pasted string with your copy and decide what you actually do forward... this might not be the best solution - but first explain us what are you trying to do and maybe someone has a better idea.

//also if i remember correctly (not sure about this so you should consult the documentation) the QClipboard class has a changed signal, so you can be noticed when the user copy something on other application and dump your old copy of the html string.

wysota
18th December 2012, 20:54
Your goal is very strange. Usually it is the copying application that decides on the data format it is preparing and the target application only accepts some formats and rejects others, it doesn't care where the data comes from. Usually I'd suggest to reimplement all the drop related actions to accept both text/html and text/plain. If you really insist on having the functionality you seek then you need to teach your application to prepare the data in a custom mime format (e.g. text/x-mycustomapplicationformat) and tell your application to reject text/html but accept text/plain and text/x-mycustomapplicationformat. Your app needs to treat the latter as HTML.

Qiieha
19th December 2012, 09:33
Thank you guys.
Your advices helped very much....

Added after 1 23 minutes:

Hi,
ok I followed wysotas advice and reimplementes the drag/drop(copy/paste) methods of QTextEdit....

In create createMimeDataFromSelection I create a new QMimeData Object and the ownership is transferred to the caller...but who deletes the QMimeData object?

thanks

wysota
19th December 2012, 10:05
but who deletes the QMimeData object?
Qt will take care of it when it is no longer needed.