I didn't tell you to connect it directly to the action enabled() slot. The clipboard can contain data you cannot paste or be empty, in which case you still do not want the paste action active.
Something like this during setup:
myUpdateClipboardStateSlot(); // sets the initial state
connect(qApp->clipboard(), SIGNAL(dataChanged()), SLOT(myUpdateClipboardStateSlot())); // and follows changes
myUpdateClipboardStateSlot(); // sets the initial state
connect(qApp->clipboard(), SIGNAL(dataChanged()), SLOT(myUpdateClipboardStateSlot())); // and follows changes
To copy to clipboard, switch view to plain text mode
and then:
void MyObject::myUpdateClipboardStateSlot()
{
const QStringList formats
= qApp
->clipboard
()->mimeData
()->formats
();
if ( [[a format I can handle is in the list]] ) // or you can call hasText(), hasHtml()...
pasteAction.setEnabled(true);
else
pasteAction.setEnabled(false);
}
void MyObject::myUpdateClipboardStateSlot()
{
const QStringList formats = qApp->clipboard()->mimeData()->formats();
if ( [[a format I can handle is in the list]] ) // or you can call hasText(), hasHtml()...
pasteAction.setEnabled(true);
else
pasteAction.setEnabled(false);
}
To copy to clipboard, switch view to plain text mode
It's also hinted at in the Drag and Drop docs
Bookmarks